aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/contentscript.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r--app/scripts/contentscript.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index a256a3f5b..1b7b98ec9 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,5 +1,7 @@
const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
const PortStream = require('./lib/port-stream.js')
+const ObjectMultiplex = require('./lib/obj-multiplex')
+
// inject in-page script
@@ -15,13 +17,22 @@ var pageStream = new LocalMessageDuplexStream({
name: 'contentscript',
target: 'inpage',
})
+pageStream.on('error', console.error.bind(console))
var pluginPort = chrome.runtime.connect({name: 'contentscript'})
var pluginStream = new PortStream(pluginPort)
+pluginStream.on('error', console.error.bind(console))
-// forward communication across
-pageStream.pipe(pluginStream)
-pluginStream.pipe(pageStream)
+// forward communication plugin->inpage
+pageStream.pipe(pluginStream).pipe(pageStream)
-// log errors
-pageStream.on('error', console.error.bind(console))
-pluginStream.on('error', console.error.bind(console)) \ No newline at end of file
+// connect contentscript->inpage control stream
+var mx = ObjectMultiplex()
+mx.on('error', console.error.bind(console))
+mx.pipe(pageStream)
+var controlStream = mx.createStream('control')
+controlStream.on('error', console.error.bind(console))
+
+// if we lose connection with the plugin, trigger tab refresh
+pluginStream.on('close', function(){
+ controlStream.write({ method: 'reset' })
+}) \ No newline at end of file