0

I'm creating a new Chrome Extension. And I have a content.js file that looks like:

console.log('here');

I have a manifest.json file that looks like:

{
  "manifest_version": 2,
  "name": "Netflix Binge Enabler",
  "version": "0.1",
  "permissions": [
    "webNavigation"
  ],
  "background": {
    "scripts": ["eventPage.js"],
  },
  "content_scripts": [
    {
      "matches": [
        "http://www.netflix.com/*"
      ],
      "js": ["jquery-2.1.3.min.js", "content.js"]
    }
  ]
}

eventPage.js:

console.log('here2');
chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
  console.log('Page uses History API');
});

When I go the netflix.com I get the appropriate 'here' string to show up in the console, but once I navigate to a movie/TV show, I don't get a second 'here' even though the URL changes.

UPDATED: When I try to add a listener to the onHistoryStateUpdated event, nothing triggers when I change pages. The initial console.log('here2') doesn't fire at all so it seems like the background page isn't working properly. Might need to send an event from the content.js page or something?

Thanks!

Shail Patel
  • 1,764
  • 5
  • 30
  • 46
  • For starters, 1) background page: see the docs for `chrome.tabs.onUpdated` or `chrome.webNavigation.onHistoryStateUpdated` 2) content script only: find and use the DOM event netflix triggers to signal the page transition like shown in ["spfdone" on youtube](http://stackoverflow.com/a/32277150/3959875). I'll add a more complete answer later unless there's a better one or a duplicate one. – wOxxOm Nov 26 '15 at 03:31
  • @wOxxOm a netflix complete answer would help greatly for me, thanks. – Shail Patel Nov 27 '15 at 18:11
  • @wOxxOm I tried to add a listener to `onHistoryStateUpdated` like in the link Xan posted, but couldn't get it to trigger properly. I'll update my question with what I've tried. – Shail Patel Nov 27 '15 at 18:45
  • @wOxxOm in that answer, the content script code is YouTube specific (looks at the red progress bar at the top of the screen to trigger events). I can't seem to find something similar about Netflix that I could listen to – Shail Patel Nov 27 '15 at 18:49
  • @ShailPatel, [Where to read console messages from background.js in a Chrome extension?](http://stackoverflow.com/a/10258029) – wOxxOm Nov 27 '15 at 19:01
  • @wOxxOm aha thank you! – Shail Patel Nov 27 '15 at 19:04

0 Answers0