Reputation: 227
I'm trying to add a content script to a tab when the tab loads, but my code is throwing
TypeError: window.QueryInterface is not a function'
when I run the attachTo method.
var attachTo = require('sdk/content/mod').attachTo;
var style = require('sdk/stylesheet/style');
tabs.on('ready', function(tab) {
var worker = tab.attach({
contentScriptFile: ['./content.js']
});
var s = style.Style({
uri: './style.css'
});
attachTo(s, tabs.activeTab.window); <------------ causes the error
array.add(pageWorkers, worker);
mainListener(worker);
});
Any ideas?
Upvotes: 4
Views: 146
Reputation: 43052
The error message suggests that attachTo
expects an XPCOM object. activeTab.window
returns a wrapper object around the native window. The high level APIs of the sdk generally deal in javascript wrapper objects that hide most of the internals.
You can use modelFor
and viewFor
to convert between those.
Upvotes: 2