TypeError: [API] is undefined in content script or Why can't I do this in a content script?

前端 未结 2 710
甜味超标
甜味超标 2020-11-27 07:21

I was trying to write a simple extension in Firefox wherein I modify the X-Frame-Allow header.

I looked at the documentation briefly and I see that they

2条回答
  •  清酒与你
    2020-11-27 08:13

    This question led me here. I had a problem with a browserAction. This line was in my background.js for handling a click on my extensions' icon:

    browser.browserAction.onClicked.addListener(handleClick);
    

    That line gave me this error:

    TypeError: browser.browserAction is undefined

    What was the problem? I just forgot to define a browser_action in my manifest.json:

    "browser_action": {
        "default_icon": "my-icon.png"
    }
    

    Maybe this hint could be helpful for someone else… ;-)

提交回复
热议问题