I’m not sure what you mean by page script
.
For content scripts, I was afraid this would happen (but hoped it wouldn’t). The browser
API is a property of the global object (this
in non-strict functions without explicit this
) and can thus be used as if it were defined as a variable. Usually in browsers, the global object is the window
object is the global object (so that this === window
is true
). In content scripts (in Firefox) that was not the case the last time I checked. Here this.__proto__ === window
is true. The browser
API is defined on the global this
and not on the window. .contentWindow
will give you a reference to the window
of the frame, which is not the global this
of content scripts in that frame. I think it is very arguable whether that is a good design.
Anyway, to fix that, this should work:
Add this as the first "content_script"
to your manifest:
{
"matches": ["Pattern matching the URLs of all frames to be handled"],
"all_frames": true,
"match_about_blank": true,
"run_at": "document_start",
"js": ["define-api.js"]
}
In define-api.js
put:
Object.defineProperty(window, "brower", { value: this.browser, enumerable: true, });
That should fix the missing .browser
reference on .contentWindow
s. (I haven’t tested it, but something like this should work.)