jack-zheng
10/12/2018 - 11:25 AM

extension, chrome, js

extension, chrome, js

Refresh Page To Let Content Script Work

Scenario: write a conent script to print github website URL, when navigate between tab like 'issues', 'pulls', it not work.
but if you reload/refresh page, it would be work.

this is because the content script is loaded when you access github page the first time, and extension not treat the tab navigation as page navigation.
fire the console and click tab, you can see, there is no page load but ajax request.
if you really want to trigger your script when click tab, you need the help of background.js and add listener to event like webNavigation.onHistoryStateUpdated or weRequest.onCompleted.