1

I have the following simplified bookmarklet in Firefox which I am attempting to convert to a webextension:

javascript:void%20function(){myobject.command(%22check%22,%22%22,this,%22%22)}();

It works without any problem when I click on the bookmarklet and myobject.command gets run. myobject is created on my.website.com and provides several command that I can run via javascript.

As I would like to click on an icon in my taskbar rather than a link in my bookmarks, I have tried to convert this to a webextension/addon by adding this command to a simple content script (content.js):

console.log("Hello");
myobject.command("check","",this,"");
console.log("Thanks for helping!");

My manifest.json contains:

"content_scripts": [
{
    "matches": ["*://my.website.com/*"],
    "js": ["content.js"]
}]

And this ensures that the content script only gets run on my.website.com. The first console.log statement gets shown when content.js runs but not the second as the script fails at the myobject.command line. The error message is "myobject is not defined".

What am I doing wrong? Why does the bookmarklet work but the content script does not?

user1464409
  • 1,032
  • 5
  • 18
  • 31

1 Answers1

0

This was a scope problem and resolved using the following answers:

user1464409
  • 1,032
  • 5
  • 18
  • 31