javascript - Is there any way to load a local JS file dynamically? -


for development purposes, i'd able load locally-stored scripts browser instead of having copy-paste console.

creating new <script> element isn't working, gives not allowed load local resource: file://.... error (in chrome).

also, creating userscript won't work--i'd have re-install every time make edit.

is there alternative way load local script via bookmarklet/etc?

in chrome, can create extension holds of local files need load. make files accessible via chrome-extension://... instead of file://...

make file named manifest.json in new folder , fill with:

{   "name": "file holder",   "manifest_version": 2,   "version": "1.0",   "web_accessible_resources": ["test.js", "other.js", "yetanother.js"] } 

then, put scripts want load in new directory, , make sure included in web_accessbile_reources manifest list. load extension going chrome://extensions, enabling developer mode, , selecting new folder load unpacked extension....

now can access files in extension directory using chrome-extension://[app_id]/[file_name], "app_id" hash listed extension on chrome://extensions page. note because protocols , hostnames differ you've doing actual work (unless decide development in extension folder, might acceptable you), extension resources cross-domain , can loaded via <script> tag.

now console, can do:

var s = document.createelement("script"); s.src = "chrome-extension://aefigdoelbemgaedgkcjpcnilbgagpcn/test.js"; document.body.appendchild(s); 

(assuming file test.js , app id aefigdoelbemgaedgkcjpcnilbgagpcn.)

it's quite bit type, know, perhaps can store chrome-extension://[app_id] part shorthand variable?


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -