Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zombie
Last active December 30, 2015 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zombie/7759981 to your computer and use it in GitHub Desktop.
Save zombie/7759981 to your computer and use it in GitHub Desktop.
contentScriptWhen
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