1

I'm trying to write my first extension with Firefox Addon SDK - current code is just testing what is possible (just to clarify).

Problematic part seems to be extension not working after first load of the page and moving beetween subpages. Page loads fully, extension "kicks in" and modifies page as supposed to (on site.com/directory for example), but after moving to subpage (site.com/directory/all) extension no longer works. If I do CTRL + R and refresh page, site loads again and extension works even on that subpage.

main.js

// Import the page-mod API
var pageMod = require("sdk/page-mod");
// Import the self API
var self = require("sdk/self");
// Create a page mod
pageMod.PageMod({
  include: "*",
  contentScriptFile: [self.data.url("jquery-2.1.1.min.js"), self.data.url("script.js")]
});

script.js

$(".directory_header").css('border', '#500 solid 10px');

Include is set like this just for testing purposes. Site script is supossed to work on twitch.tv and their /directory subpage. Currently looking for directory_header class and setting border around it, however after moving to directory/all border will not load again until the page is reloaded fully. Is there a reason for this behaviour?

What Ive tried

I tried to use

attachTo: ["top", "frame", "existing"]

which from first look seemed like it could help, but it did not. Similar with

contentScriptWhen: 'start'

again, with no result.

poss
  • 1,759
  • 1
  • 12
  • 27
  • Yes you have to iterate through all windows and all tabs on startup and attach to them if you want to run right away. Make sure to iterate through all windows and tabs on unload to unload them on uninstall. This is how I do it in my bootstrap addons. – Noitidart Sep 18 '14 at 07:23

1 Answers1

2

It sounds like HTML5 state changing, where the contents of the page are being changed through AJAX. The document/page isn't actually changing, so page-mod will never be activated. You'll need to create a listener in the content script for the history pushstate event. See this answer on how to accomplish that.

In the callback you'll have to re-invoke your script.js code.

Community
  • 1
  • 1
willlma
  • 7,353
  • 2
  • 30
  • 45
  • @poss. Either this or it could be PJAX, which I don't think uses the pushstate perfectly so it gets real hard. If using PJAX you have to attach event listeners via the jquery of the website itself. – Blagoh Sep 26 '14 at 07:38