Skip to content

Conversation

@agoodkind
Copy link

Changes

Added two new functions:

  1. getTrueTabDomain(tabId) - Fetches the actual domain from the tab's URL (source of truth from the address bar)
  2. isMainTabUrl(details) - Validates if a request is truly for the main frame by comparing the request's domain against the tab's actual domain

Modified two locations:

  1. chrome.webRequest.onBeforeRequest - Replaced simple type check with await isMainTabUrl(details)
  2. chrome.webRequest.onBeforeRedirect - Replaced simple type check with await isMainTabUrl(details)

What this fixes

When Chrome prefetches links, it sends requests with type: "main_frame", which previously caused mainDomain to be overwritten incorrectly. The fix validates that the request's domain matches the tab's actual URL before treating it as a main frame navigation, preventing prefetch requests from corrupting the extension's state.

Before:

Screen.Recording.2025-10-18.at.21.07.29.mov

After:

Screen.Recording.2025-10-18.at.21.18.05.mov

@agoodkind
Copy link
Author

@pmarks-net This fixes #71

@pmarks-net
Copy link
Owner

pmarks-net commented Oct 27, 2025

I found a preliminary solution. It's called from the same places as await isMainTabUrl in your PR.

function isProperMainFrame(details) {
  if (details.type == "main_frame" || details.type == "outermost_frame") {
    if (details.documentId) {
      // It seems that a main_frame request with a documentId refers to some kind
      // of prefetch, rather than a top-level navigation to a new URL.
      console.log("Preloaded main_frame?", details.url);
      return false;
    }
    return true;
  }
  return false;
}

Demo: https://www.google.com/search?q=real+estate

background.js:951 Preloaded main_frame? https://www.realtor.com/...
background.js:951 Preloaded main_frame? https://www.zillow.com/...

IPvFoo shows "www.realtor.com 2001:4860:4802:34::9d" and "www.zillow.com 2001:4860:4802:34::9d", which suggests that the requests are being proxied by Google. I should probably add a P/prefetch icon next to the address, because otherwise the results could be misleading. Neither of those sites actually support IPv6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants