0

I am trying to make a very simple Manifest v3 chrome extension that blocks an "automatic redirect" on a website.

I like to use an overseas online merchant ("foo.com") but when you click into a product's details, it sends me to sso.foo.com to login w/ a free account. I can tap the browser stop button when the product page shows up, but before the "redirect" executes (i think its more like a JS triggered window.location) - and i can work around it that way; but i'd rather just make a chrome extension for myself that blocks this.

I tried creating a declarative_new_request that blocks requests to sso.foo.com

[{
    "id" : 1,
    "priority": 1,
    "action" : { "type" : "block" },
    "condition" : {
      "urlFilter" : "sso.foo.com",
      "domains" : ["foo.com"],
      "resourceTypes" : ["script", "main_frame", "sub_frame"]
    }
}]

...And this almost works, however the browser blocks the "end" of the request to https://sso.foo.com - so instead of "stopping" on the Product page, i see a chrome page saying "sso.foo.com" was blocked by an extension. What i want, is to block the navigation to https://soo.foo.com/* but leave me on the current page ... is this possible? Thoughts on how i can do this?

empire29
  • 3,729
  • 6
  • 45
  • 71

1 Answers1

1

For script resource type you can try redirecting to a data URL:

"action" : { "type" : "redirect", "url": "data:," },

The main_frame and sub_frame navigation cancelling is not implemented yet.
Please star https://crbug.com/943223 to raise its importance.

The workaround

Assuming the page is using an <a> link you can declare a content script with a click listener in the capturing phase that hides this event from the page.

manifest.json:

"content_scripts": [{
  "matches": ["*://*.foo.com/*"],
  "js": ["content.js"],
  "run_at": "document_start"
}]

content.js:

window.addEventListener('click', ev => {
  const a = ev.target.closest('a');
  if (a?.hostname === 'sso.foo.com') {
    ev.stopPropagation();
    ev.preventDefault();
  }
}, true);
wOxxOm
  • 65,848
  • 11
  • 132
  • 136