Created
September 1, 2011 01:56
-
-
Save vroy/1185231 to your computer and use it in GitHub Desktop.
Jetpack - Change window location from content script.
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
console.log("Starting content script."); | |
console.log( window.location ); | |
window.location = "http://www.google.com/"; | |
console.log( window.location ); | |
console.log( window.location.host ); |
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
var data = require('self').data; | |
require('page-mod').PageMod({ | |
include: "*", | |
contentScriptWhen: 'ready', | |
contentScriptFile: [ data.url('example.js') ] | |
}); | |
console.log("Addon loaded."); |
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
info: Addon loaded. | |
info: Starting content script. | |
info: http://www.facebook.com/ | |
info: http://www.google.com/ | |
info: undefined |
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
Using the addon-sdk from github.com/mozilla/addon-sdk with this patch applied: https://bugzilla.mozilla.org/attachment.cgi?id=555753&action=edit | |
As you can see in the output, the location does seem to change but when I hit facebook.com and the output shows that I should be on google.com, I still see facebook.com. Is it possible to change the location of a page from within the page-mod's content script? | |
I would also like to point out that window.location.host returns undefined. I thought it would make sense that window.location in the context of a content script should return a standard Location object as described by the MDN docs: https://developer.mozilla.org/En/Window.location#Location_object | |
I'm guessing the workaround is to send messages to the add-on code and use the tabs API but I would rather avoid that to keep my extension code as much similar to other browser extensions as possible. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment