Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nifty tip. Let's try it, and see if it works.

Edit: Sorry bud. I gave it a shot, and `activeTab` doesn't allow you to modify the "Referer" header.



Yeah, if you really want to do this, you can use chrome.permissions with "optional_permissions" set in your manifest requesting all urls -- then call permissions.request() on invocation to add a specific host.

See: https://developer.chrome.com/extensions/permissions


There is always the option of not messing with the request at all. Instead actually have it redirect through google. For example you could have the background script do:

  chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.executeScript({
      code: 'window.stop(); window.location = "http://www.google.com/badurl/' + encodeURIComponent(tab.url) + '";' 
    });
  });
and then you can have a content script run on "http://www.google.com/badurl/*" which just does:

  window.location = decodeURIComponent(window.location.pathname.split("/")[2]);
Now that is super brittle compared to your solution, but it does work(for the sites I tried, some may require you to actually fake a search query). It only requires the activeTab permission and content script permissions on one page.


You could dynamically (and temporarily - use chrome.permissions.remove when the tab navigates or closes) request the webRequest permission for the current host when the user clicks the browser action icon. Yes, that would mean clicking again to confirm whenever the user wants to use the extension, although it's possible that Chrome will remember what permissions have been granted and not prompt the user for future use on the same site.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: