Skip to content

Instantly share code, notes, and snippets.

@ajitid
Last active April 27, 2023 05:29
Show Gist options
  • Save ajitid/1540176c37cde825bb9170590c0e4522 to your computer and use it in GitHub Desktop.
Save ajitid/1540176c37cde825bb9170590c0e4522 to your computer and use it in GitHub Desktop.
Load scripts in Chrome by putting this in DevTools > Sources > Snippets
  1. Run the script
  2. Use it like: loadScript('https://unpkg.com/@testing-library/dom/dist/@testing-library/dom.umd.js')

You'll need a UMD build or any browser compat build for this. If you see an error similar to

then you'll have to copy paste that JS file into Snippets and run it manually

'use script'
function loadScript(filePath, cacheBuster = `?bust=${new Date().getTime()}`) {
const scriptTag = document.createElement('script');
scriptTag.onload = () => console.log('loaded');
scriptTag.type = 'text/javascript';
scriptTag.src = `${filePath}${cacheBuster}`;
document.querySelector('head').appendChild(scriptTag);
}
window.loadScript = loadScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment