Extension doesn't load on first page load. Have to refresh

11 views
Skip to first unread message

Velius Developer

unread,
9:50 AM (3 hours ago) 9:50 AM
to Chromium Extensions
Hello. I'm new to writing Chrome extensions, but an experienced dev.  I wrote a chrome extension designed to only show up on a certain game page of NY Times website. The first time I go to that page, the extension doesn't show.  

I've narrowed the error down to an HTTP 403 (Forbidden) error during the extension load.  It is using a "fetch" to retrieve the HTML of the hints page of the game. It has the correct URL which it retrieved from the main game page that it should be loading on.

This fetch USED TO work fine every time, and now it still works if I FORCE refresh of the page (Ctrl-F5).

I am not sure when this problem started happening. I assume it's due to some change in the nytimes.com website, but I am not sure how to approach fixing this problem.

Would appreciate suggestions from experienced chrome extension devs. Thank you!

woxxom

unread,
10:12 AM (2 hours ago) 10:12 AM
to Chromium Extensions, Velius Developer
Without seeing the code I guess the problem is that those games are SPA (Single-Page Apps), so the `document` stays the same, only the URL is faked via history API and DOM is patched directly. You can see it in devtools network panel when navigating inside - there'll be no request with the type of "document". A content script is only injected when the `document` is created, so it won't happen when the initial URL in the tab wasn't a matching one and then you navigated to a URL that should be matching. To match such sites your "matches" for the content script should comprise the entire app e.g. "https://www.nytimes.com/puzzles/sudoku/*", then the content script should listen to navigation either by using navigation.onnavigatesuccess event or by using MutationObserver on `document`.
Reply all
Reply to author
Forward
0 new messages