Saurabh Agarwal
Saurabh Agarwal

Reputation: 527

How to get a DOM Window reference for a Google Chrome Extension?

I am porting a firefox extension to google chrome built using GWT.

In the linker, I need to specify $wnd and $doc variables.

The equivalent in firefox is as follows:

var $wnd = Cc["@mozilla.org/appshell/appShellService;1"].getService(Ci.nsIAppShellService).hiddenDOMWindow;
var $doc = $wnd.document;    

The attribute hiddenDOMWindow as explained here returns the (singleton) application hidden window, automatically created and maintained by this AppShellService and is Read only.

Upvotes: 0

Views: 998

Answers (2)

Wladimir Palant
Wladimir Palant

Reputation: 57651

Background scripts in Chrome extensions always run inside a window (the background window). So you can just access your own window from the background script:

var $wnd = window;
var $doc = $wnd.document;

Upvotes: 2

Dmitrii Sorin
Dmitrii Sorin

Reputation: 4016

There is getViews() method in chrome.extension API. You can get window's document using this method.

Upvotes: 0

Related Questions