Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add custom request headers when using chrome custom tabs?

Planning to use chrome custom tabs, however before I start I wanted to know if its possible to intercept the request and set any headers in the request similar to WebViews ?

Read through the documentation and could not find any examples or references. All I could find is the onNavigationEvent callback that tells what url browser is trying to load.

Also is it possible to stop navigation for any url if required ?

like image 284
ksarmalkar Avatar asked Nov 16 '15 21:11

ksarmalkar


People also ask

Is it possible to add custom header?

In the Home pane, double-click HTTP Response Headers. In the HTTP Response Headers pane, click Add... in the Actions pane. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.

Can an HTTP request have custom headers?

Custom HTTP headers can be used to filter requests or specify a value for the Accept header.


2 Answers

As of recent updates of the library, you can now add Bundle and pass it to the CustomTabsIntent intent as extra with key Browser.EXTRA_HEADERS

Bundle headers = new Bundle();
headers.putString("header1", "value1");
headers.putString("header2", "value2");
customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
like image 145
Alireza Ghanbarinia Avatar answered Oct 26 '22 11:10

Alireza Ghanbarinia


I managed to inject http headers for the first tab following this way: https://medium.com/@_rpiel/chrome-custom-tabs-and-headers-or-a-happy-open-source-story-9c3f82680eea#.l46alsivf

I don't think that it's supported for subsequent tabs for now.

like image 41
Romain Piel Avatar answered Oct 26 '22 09:10

Romain Piel