Skip to content

Instantly share code, notes, and snippets.

@jsantell
Last active August 29, 2015 14:04
Show Gist options
  • Save jsantell/d0b84e8f20abb24a44d7 to your computer and use it in GitHub Desktop.
Save jsantell/d0b84e8f20abb24a44d7 to your computer and use it in GitHub Desktop.
e10s frame script utils usage
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
const FRAME_SCRIPT_UTILS_URL = "chrome://browser/content/devtools/frame-script-utils.js"
function navigateInHistory(aTarget, aDirection, aWaitForTargetEvent = "navigate") {
// if e10s, use the message manager
if (Cu.isCrossProcessWrapper(content)) {
let mm = gBrowser.selectedBrowser.messageManager;
mm.loadFrameScript(FRAME_SCRIPT_UTILS_URL, false);
mm.sendAsyncMessage("devtools:test:history", { direction: aDirection });
}
// Otherwise just access content directly
else {
executeSoon(() => content.history[aDirection]());
}
return once(aTarget, aWaitForTargetEvent);
}
@zombie
Copy link

zombie commented Jul 30, 2014

frame script might not be loaded yet when you sendAsyncMessage().. the simplest solution is to use sendSyncMessage() from the frame script, and set up a message listener in the chrome code that does return { direction: aDirection }.

also, i don't think you need two code paths, you can just use the frame script in both cases, it works without e10s too..

@zombie
Copy link

zombie commented Jul 30, 2014

actually, according to billm:

@billm> zombie_: it should be fine to do loadFrameScript and then sendAsyncMessage. the message won't be processed until the frame script has run.
00:51 @billm zombie_: so as long as the frame script immediately adds a listener for the message, it will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment