0

I am testing window.location.replace to redirect the current URL to a new one. It works fine when the URL in the window.location.replace is for another internet website (e.g. google.com). But, it does not work when the URL points to a local html document.

There is a similar problem posted here and the solution suggests adding a permission key to the package.json file. I tried this but it did not solve the problem. I also think that the extension's local files in SDK extensions are considered safe and do not need permission.

Assume the following javascript in a Firefox SDK addon:

var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  include: "*.yahoo.com",
  contentScriptWhen: "start",
  contentScript: 'window.location.replace("/data/page.html");'

});

And this manifest.json file:

{
  "title": "My Jetpack Addon",
  "name": "example",
  "version": "0.0.1",
  "description": "A basic add-on",
  "main": "index.js",
  "author": "",
  "engines": {
    "firefox": ">=38.0a1",
    "fennec": ">=38.0a1"
  },
  "license": "MIT",
  "keywords": [
    "jetpack"
  ]
}

Here is the address bar appending the URL that I want to redirect the URL to. I need to replace the URL not to append it.

enter image description here

user6875880
  • 651
  • 1
  • 7
  • 17

1 Answers1

0

You would want to use the full URL of your page, and not just an absolute URL inside your extension. See the "myWebsite" variable passed to the content script in the question you linked to.

humanoid
  • 754
  • 3
  • 17