Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.open in background.js in firefox extension?

I am converting a working chrome extension to a firefox extension. In the extension, it calls window.open() in the background.js. However, it is not working in my firefox version, and I have tested that everything else is working fine, and it is just not window.open'ing.

I read online that it could be due to a security issue? How do I adjust the security settings so it will be able to run, and how do I notify the user to?

manifest.json

{
"manifest_version": 2,
"name": "Instagram Liker",
"description": "Instagram Liker",
"version": "1",
"icons": {
    "16": "icon16.png",
    "48": "icon48.png",
    "128": "icon128.png"
},
"content_scripts": [
    {
        "matches": [
            "<all_urls>"
        ],
        "js": [
            "js/custom.js"
        ]
    }
],
"background": {
    "scripts": [
        "js/background.js"
    ]
},
"browser_action": {
    "default_popup": "popup.html"
}

}

The window.open is just being called in a function in the background.js, I don't think I need to post that code.

like image 248
anduyang Avatar asked Oct 24 '25 09:10

anduyang


2 Answers

I encounter exactly the same problem, solution is to not use

window.open("yourUrl")

but instead use method provided only for browser extensions

browser.windows.create({url: ""yourUrl""});

With this solution you can be sure your event page won't be blocked by any popup blocker.

like image 172
Bartosz546 Avatar answered Oct 26 '25 23:10

Bartosz546


It worked for me without the double "":
browser.windows.create({url: yourUrl});

like image 28
AndresB Avatar answered Oct 26 '25 23:10

AndresB