Last active
December 30, 2015 01:59
-
-
Save zombie/7759981 to your computer and use it in GitHub Desktop.
contentScriptWhen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tabs = require('sdk/tabs'); | |
const { PageMod } = require('sdk/page-mod'); | |
let s = "var x = 'start';" + | |
"addEventListener('DOMContentLoaded', () => x = 'ready');" + | |
"onload = () => x = 'end';"; | |
let url = "data:text/html,<script>" + s + "</script> hey there"; | |
let whens = ['start', 'ready', 'end']; | |
whens.forEach(function(when) { | |
new PageMod({ | |
include: 'data:*', | |
contentScriptWhen: when, | |
contentScript: 'self.postMessage(unsafeWindow.x)', | |
onAttach: function(wrk) { | |
wrk.on('message', function(msg) { | |
console.log(when, msg); | |
}) | |
} | |
}); | |
}) | |
tabs.open({ | |
url: url, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment