0

im writing my own javascript library at the moment and want to permanently import it to the microsoft edge devtools console (or devtools in general), to use it there,but i dont know how to import it

thanks in advance, -Gzrespect

Gzrespect
  • 13
  • 2
  • do you have localhost? then just `await import('http://localhost:1234/file.js')` – Dimava Nov 18 '22 at 15:22
  • whats the file path then? cuz i have the lib a few folders deep in my system also i want it to stay imported permanently,not import it again everytime i use the console – Gzrespect Nov 18 '22 at 15:24
  • You will probably have to build & bundle the library (in a single file). Then, maybe you can look at building a wrapper browser extension, which wraps your library and provides global object[s] to play around with your lib. – vighnesh153 Nov 18 '22 at 15:25
  • Depending on _library_ you can just create Bookmarklet that will execute JS code on bookmark click – Justinas Nov 18 '22 at 15:28
  • Does this answer your question? [Function as Google Chrome bookmark](https://stackoverflow.com/questions/18872679/function-as-google-chrome-bookmark) – Justinas Nov 18 '22 at 15:28

1 Answers1

0
  1. If you don't have a local server, get one at https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb/ and set up a folder to serve.

  2. set CORS in advanced server settings to allow importing it on most websites

  3. use let myModule = await import('http://127.0.0.1:8887/myModule.ts') to import it


note: that should be ES module (with imports if there are multimple files) and not CJS module (with requires)

Dimava
  • 7,654
  • 1
  • 9
  • 24
  • is it possible to either automatically import it on devtools start or have it permanently imported? – Gzrespect Nov 18 '22 at 16:14
  • @Gzrespect You may use userscript extension to import it specific websites, like https://chrome.google.com/webstore/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld or Tampermonkey – Dimava Nov 18 '22 at 18:41