Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't ContentScriptFile work in PageMod?

I try to inject content script on page and use

console.log("starting addon");
pageMod.PageMod({
    include: "*",//tempopary
    contentScriptFile: self.data.url("testPreload.js"),
    contentScriptWhen: 'start'});

testPreload.js:

console.log('testPreload');

I see "starting addon" in log and if I use contentScript:"console.log('testPreload')" instead of contentScriptFile I also see "testPreload".

But when I use contentScriptFile I see "starting addon" but not "testPreload". What am I doing wrong?

EDIT Error: Error opening input stream (invalid filename?) filePath resource://jid1-ktaxagdysynpew-at-jetpack/extension/data/testPreload.js

like image 655
Suhan Avatar asked Mar 26 '14 09:03

Suhan


2 Answers

You want to move your testPreload.js file into the data directory. The self.data module is actually referencing that directory so the self.data.url() function gives you a valid URL to the files in that directory. FYI those URLs tend to look like resource://[your-jetpack-id]/data/[file])

Again, just move your: lib/testPreload.js to data/testPreload.js and that should fix the problem.

like image 63
Bryan Clark Avatar answered Oct 21 '22 16:10

Bryan Clark


Your contentScript Files should reside in data directory to be able to access it through self.data.url('scriptname') .
Move your testPreload.js to data directory.

See https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/Loading_Content_Scripts

like image 44
abhishekkannojia Avatar answered Oct 21 '22 16:10

abhishekkannojia