Android- EXTRA_HEADERS 在更新版本大于 83 的 Chrome 中未反映出来

huangapple go评论49阅读模式
英文:

Android- EXTRA_HEADERS is not reflecting in updated Chrome version greater than 83

问题

之前传递给customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers)EXTRA_HEADERS在Chrome更新到83之前是正常工作的。更新后,不再传递头部数据。

public static void startCustomTab(String url, Context context) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setShowTitle(true);
    CustomTabsIntent customTabsIntent = builder.build();
    Bundle headers = new Bundle();
    headers.putString(context.getString(R.string.type), "android");
    headers.putString(context.getString(R.string.source), "app");
    customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    customTabsIntent.launchUrl(context, Uri.parse(url));
}
英文:

Earlier the EXTRA_HEADERS passed to the customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers), was working fine. After Chrome updated to 83, it stopped passing the header data.

   public static void startCustomTab(String url, Context context) {
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent customTabsIntent = builder.build();
    builder.setShowTitle(true);
    Bundle headers = new Bundle();
    headers.putString(context.getString(R.string.type), "android");
    headers.putString(context.getString(R.string.source), "app");
    customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers);
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    customTabsIntent.launchUrl(context, Uri.parse(url));
}

答案1

得分: 3

自定义标头的添加已被删除,因为它是一种漏洞。跨源资源共享(CORS)白名单请求标头仍然受支持。您可以在此处阅读更多关于此更改的信息:http://crbug.com/873178

英文:

Adding custom headers was removed due to being a vulnerability. CORS safe-listed request headers are still supported. You can read more about this change here: http://crbug.com/873178

答案2

得分: 3

我想详细说明一下接受的答案。 Chrome 83确实删除了添加自定义标头的可能性,但Chrome 86在某些严格条件下恢复了此功能。请参阅https://developers.google.com/web/android/custom-tabs/headers。只需按照https://github.com/GoogleChrome/android-browser-helper/tree/master/demos/custom-tabs-headers中的示例进行操作。

TD;DR - 您必须拥有应用程序和网站,以使其在应用程序和数字资产链接协议文件(网站地址 (...)/.well-known/assetlinks.json)中的更改生效。

请确保按照教程和示例精确执行。在我的情况下,我遇到了一个细节问题 - CustomTabsIntent Builder需要设置一个CustomTabsSession对象。

在Chromium项目中引入更改的代码更改可以在此处找到:https://chromium-review.googlesource.com/c/chromium/src/+/2311582

英文:

I'd like to elaborate a bit on the accepted answer. The Chrome 83 indeed removed the possibility to add custom headers, yet Chrome 86 reverted this functionality under certain strict conditions. See https://developers.google.com/web/android/custom-tabs/headers. Just follow an example from https://github.com/GoogleChrome/android-browser-helper/tree/master/demos/custom-tabs-headers.

TD;DR - you must own both app and website for making it work as the changes in app and The Digital Asset Links protocol file (website address (...)/.well-known/assetlinks.json) are needed.

Be sure to follow the tutorial and example precisely. In my case I stumbled with the one detail - CustomTabsIntent Builder needs a CustomTabsSession object set up.

Code changes in Chromium project indroducing a change can be found here: https://chromium-review.googlesource.com/c/chromium/src/+/2311582

huangapple
  • 本文由 发表于 2020年7月30日 16:05:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63168798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定