Muthu
Muthu

Reputation: 357

Set Headers for a URL opened from chrome extension

I will open a URL in a new tab from my chrome extension using chrome.tabs.create() method. My problem is that I need to set a header on opening the URL, so that it is listened from the server side. How to set a header for the URL that is been opening?

Upvotes: 1

Views: 2469

Answers (2)

Scott
Scott

Reputation: 1042

I'm assuming you mean the HTTP Request headers, in which case there is a way to modify HTTP Request headers for requests as they go out the door, using the chrome.webRequest.onBeforeSendHeaders API found here. Let's say that you know you're going to create a new tab with a specific URL. You can setup a listener for the onBeforeSendHeaders API prior to creating the new tab. In the handler for that, you would only consider URLs that match that URL. You could then modify the header, and optionally un-instrument your onBeforeSendHeaders API (might need to do via a setTimeout or something).

Upvotes: 1

Mdbook
Mdbook

Reputation: 39

This is a little unclear. Could you give me the source code of your extension? I suppose you could do it with the <title> HTML element, if that's what you're asking

Upvotes: -1

Related Questions