You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 12, 2020. It is now read-only.
This is an idea to allow requirejs' style to include files from the scripts. Currently we only have the default.js and it's getting cluttered for me, so thought about how to make this feature possible.
Interaction
The basic idea is that main.js will inject bridge.js, which will expose the require function to the browser in order to communicate with the nodejs environment.
The main.js will match the files and include them. When these call require, the bridge will emit an event, main.js will require the files and emit the results back to the bridge, which will notify the scripts.
Please note that this is more like a draft of the idea, than an actual implementation. I have not run the code and it may contain subtle bugs :)
1. main.js
Here we are at nodejs.
We need to add the listener for the bridge, in which we will require the files and send the back. Other than that, the file wont need any other modification.
worker.port.on('.js:require-req',function(req){try{worker.port.emit('.js:require-ret',{id: req.id,result: deps.map(function(dep){returnrequire(dep)}),})}catch(err){worker.port.emit('.js:require-err',{id: req.id,error : err,})}});worker.port.on('init',function(domain){// 1. inject the worker.port.emit('load-scripts','bridge.js');// 2. match + emit load-scripts as usual// ...})
2. bridge.js
We are at browser-side, so we declare the window.require shim and declare the hooks required for IPC
However, I'm pretty sure this whole addon needs to be reimplemented somehow using WebExtensions since the addon sdk and this style of addons will stop working soonish (I think it's Firefox 57?). So, I'll need to look into that and see if it's even possible.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Allow to
require
filesThis is an idea to allow requirejs' style to include files from the scripts. Currently we only have the
default.js
and it's getting cluttered for me, so thought about how to make this feature possible.Interaction
The basic idea is that
main.js
will injectbridge.js
, which will expose therequire
function to the browser in order to communicate with the nodejs environment.The
main.js
will match the files and include them. When these callrequire
, the bridge will emit an event,main.js
will require the files and emit the results back to the bridge, which will notify the scripts.Implementation
Please note that this is more like a draft of the idea, than an actual implementation. I have not run the code and it may contain subtle bugs :)
1. main.js
Here we are at nodejs.
We need to add the listener for the bridge, in which we will require the files and send the back. Other than that, the file wont need any other modification.
2. bridge.js
We are at browser-side, so we declare the
window.require
shim and declare the hooks required for IPC3. script
This could be an example of a script, that make usage of the
require
shim.The text was updated successfully, but these errors were encountered: