content-scripts-register-polyfill icon indicating copy to clipboard operation
content-scripts-register-polyfill copied to clipboard

Content script doesn't inject on page load from shorthand url

Open twschiller opened this issue 1 year ago • 0 comments

Step to Reproduce

  • Version 3.2.2 (imported via webext-dynamic-content-scripts version 9.2.2)
  • Grant optional permissions to https://www.linkedin.com/*
  • Open a new tab and type: linkedin.com
  • If you're logged in, page will redirect to https://www.linkedin.com/feed/
  • Content script is not injected 😞

Discussion/Investigation

  • browser.webNavigation.onHistoryStateUpdated is fired for the frame
  • browser.webNavigation.onCommitted is fired for the frame: image
  • ~~Somehow previouslyLoaded is coming back as true~~: my debug logging might have messed this up. It's confusing that wasPreviouslyLoaded mutates the state
  • There's something fishy going on with the frameIds/variable namespace. Somehow https://www.linkedin.com first appears as being in a frame, and then the top-level inject fails due to wasPreviouslyLoaded coming back as true

image

  • The bug appears to be fixed if I pass tabId and frameId in the wasPreviouslyLoaded check
|| await wasPreviouslyLoaded({ tabId, frameId }, { js, css, tabId, frameId }) // Avoid double-injection

Other History

  • The history includes the SPA redirect to /feed/ image

Related

  • https://github.com/fregante/content-scripts-register-polyfill/pull/60

twschiller avatar May 16 '23 13:05 twschiller