0

I'm building an extension that checks for a custom TLD then serves an associated IP from a custom DNS. I've tried using chrome.proxy, as well as simple location.host parsing.

chrome.proxy has very weird behavior with a copy-paste from the docs.. reruns the background.js script 60 times or so.

location.host is never called since the "site can't be reached" error page loads and seems to disable the extension background script.

So question is how to hijack chrome's normal url behavior to hook in before the site can't be reached error or how to adjust the DNS lookup to include custom TLDs. It seems possible considering Blockchain DNS has existed since 2018 (albeit with a / workaround that will still require low-level url checks)

Many thanks in advance and please let me know what I'm failing to notice if there's no good solution.

JS in vue app's actions file:

var config = {
  mode: "pac_script",
  pacScript: {
    data: "function FindProxyForURL(url, host) {\n" +
          "  if (host == 'my.xym/')\n" +
          "    return 'PROXY localhost:8080';\n" +
          "  return 'DIRECT';\n" +
          "}"
  }
};

chrome.proxy.settings.set(
    {value: config, scope: 'regular'},
    function() {});

odd behavior is multiple calls to the same console log function and chrome.proxy being unavailable: enter image description here

irth
  • 1,696
  • 2
  • 15
  • 24
  • Without seeing [MCVE](/help/mcve) it's unclear what happens and what exactly you mean by "reruns the background.js script 60 times" as well as "disable the extension background script" as neither of these should be happening when the background script is used properly. – wOxxOm Apr 27 '20 at 09:05
  • true, i'll update – irth Apr 27 '20 at 09:06
  • @wOxxOm i've updated with what I've tried but also remembered thinking this path wasn't the right one. In any case, perhaps it'll help us solve. – irth Apr 27 '20 at 09:13
  • Looks like you're loading background.js in your app page, which is wrong because a properly declared [background script](https://developer.chrome.com/extensions/background_pages) already runs in a *separate* hidden background page ([How to see background.js console?](/a/10258029)). – wOxxOm Apr 27 '20 at 09:17
  • As for chrome.proxy being unavailable it means your manifest.json doesn't declare it in `permissions` or the code that tries to use it doesn't run in an extension page (for example you're running it manually as a `http` or `file` page so it's just a normal web page). – wOxxOm Apr 27 '20 at 09:19
  • FWIW, you can inspect the source code of that extension in [crxviewer](https://robwu.nl/crxviewer/?crx=https%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2Fblockchain-dns%2Fhlnmiaddfabbklljanmdilbngnookdgn%3Fhl%3Den). – wOxxOm Apr 27 '20 at 09:21
  • Sorry for any confusion. This is my code, working as expected, the vue js loads ahead of background.js bc background.js requires the Vuex store. Do you know that chrome.proxy is the right solution to the question? – irth Apr 27 '20 at 10:47
  • Judging by the fact that other extension is using chrome.proxy it seems the right tool. P.S. If you load background.js in an app page and it's declared in `background` section of manifest.json then you're definitely doing it wrong (maybe you don't need to declare the `background` section at all). – wOxxOm Apr 27 '20 at 10:58
  • background.js loads after, but not from, an app page. Cheers, i'll keep working on it. – irth Apr 27 '20 at 15:55
  • Well, since you didn't show manifest.json I have to guess looking at the log. If you declare background.js in `background` section in manifest.json then under no circumstances should you include it anywhere else. The fact that you do and it works for you can mean you don't actually need a background script. Anyway I didn't see an explanation of things I asked in my first comment because the console output doesn't correlate to the posted fragment of code. – wOxxOm Apr 27 '20 at 16:09
  • Ye sorry, my bad, separate problems. Thank you for the source code link before. Much appreciated. turns out i was about halfway there but it was only working from the extension tab view. I'll post back with the solution. – irth Apr 28 '20 at 16:42

0 Answers0