gpt4 book ai didi

java - Android(4.4+) WebView 忽略 x-frame-options

转载 作者:太空狗 更新时间:2023-10-29 13:58:57 26 4
gpt4 key购买 nike

我正在尝试在应用程序中显示带有 iframe 的页面。它显示简单的页面,但不能显示 googlemap iframe。

我试过:hardvre accelleration - 打开(我知道它只与视频相关),Java 脚本 - 已启用,使用网络 chrome 客户端,loadurl(因为从内存加载),等

代码是:

        wewview = new WebView(getActivity().getApplicationContext());
wewview.getSettings().setJavaScriptEnabled(true);
wewview.getSettings().setLoadWithOverviewMode(true);
wewview.getSettings().setUseWideViewPort(true);
wewview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
wewview.setWebChromeClient(new WebChromeClient());
if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
wewview.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
wewview.getSettings().setPluginState(WebSettings.PluginState.ON);
wewview.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);

linearMain.addView(wewview,0);

wewview.loadUrl("file://path... /frames.html");

有人可以建议我如何以编程方式为我的 webview 打开“忽略 x-frame-options”吗?

更新 1

在日志中发现另一条消息

05-19 10:01:49.404: I/chromium(4027): [INFO:CONSOLE(0)] "Refused to display 'https://www.google.ru/maps/@?nogmmr=1' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.", source: about:blank (0)

寻找忽略 x-frame-options

最佳答案

找到了路。加载框架上没有完整的交互,但我只需要显示它。因此,Jsoup 用于加载页面内容,但继续以标准方式加载脚本和图像,这就是所有技巧:

   private class ignoreXHeaderWebClient extends WebViewClient{  
private static final String URL_MASK = "http";


//api < 21
@Override
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
WebResourceResponse content = getsPageContent(url);
if (content != null) {
return content;
} else {
return super.shouldInterceptRequest(view, url);
}
}

// api >= 21
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
WebResourceResponse content = getsPageContent(request.getUrl().toString());
if (content != null) {
return content;
} else {
return super.shouldInterceptRequest(view, request);
}
}

private WebResourceResponse getsPageContent(String url){
if (( url.contains(URL_MASK)) // guess is better to create for ex map to check all extensions
&& !(( url.contains(".js"))
||( url.contains(".css"))
||( url.contains(".tiff"))
||( url.contains(".jpg"))
||( url.contains(".png"))
||( url.contains(".gif")))){
try {
return new WebResourceResponse(
"text/html",
"UTF-8",
new ByteArrayInputStream(
Jsoup.connect(url)
.get()
.toString()
.getBytes()));
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}

并应用新类:

webWiev.setWebViewClient(ignoreXHeaderWebClient);  

关于java - Android(4.4+) WebView 忽略 x-frame-options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37294008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com