Created
November 30, 2016 02:11
-
-
Save jaredhirsch/5699a18f749fecb0a018c59c07f4c521 to your computer and use it in GitHub Desktop.
Firefox trick: use the hidden window to access DOM APIs without a window reference
This file contains hidden or 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
// You may sometimes be doing something in non-UI add-on code, | |
// but want access to nice DOM APIs, like navigator.sendBeacon(). | |
// Use the hidden window, which is accessible via the AppShell service: | |
// If you're in an SDK addon, do this to get a Cu reference: | |
// const { Cu } = require('chrome'); | |
Cu.import('resource://gre/modules/Services.jsm'); | |
// this is your window: | |
const win = Services.appShell.hiddenDOMWindow; | |
// you can access all the APIs directly: | |
Services.appShell.hiddenDOMWindow.navigator.sendBeacon(url, data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment