New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

failed-to-load

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

failed-to-load

Find script tag that have failed to load when document's readyState is complete

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.7K
decreased by-4.56%
Maintainers
4
Weekly downloads
 
Created
Source

failed-to-load

Find script tags that have failed to load when document's readyState is complete.

Add this attribute "onload" with "this.loaded=1" in its value (onload="this.loaded=1")

<script src="my-script-922a511f02d148e4c9390526d85ca519.js" onload="this.loaded=1"></script>
<script src="other-script-693e810ff27604e6da274da4c77e136c.js" onload="this.loaded=1"></script>

Register check for window load

import { register } from 'failed-to-load';
register();

This will throw an ayncronous error to be caught by your global onerror callback.

Error{
  message: `Failed to load necessary script tags upon window load
my-script-922a511f02d148e4c9390526d85ca519.js
other-script-693e810ff27604e6da274da4c77e136c.js`,
  code: 'ERROR_NECESSARY_SCRIPT_NOT_LOADED',
  files: [
    [object HTMLScriptElement],
    [object HTMLScriptElement]
  ]
}

Alternatively, you can register a callback to catch the error (then it will not be thrown)

register(
  error => logger.warn(error)
);

Check and report manually:

import { check } from 'failed-to-load';

window.addEventListener('load', () => {
  const missing = check();
  if (missing.length) {
    logger.warn({
      message: 'script files not loaded on page load',
      files: missing.map(({ src }) => src)
    })
  }
});

FAQs

Package last updated on 06 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc