捕获“无法加载资源” < webview>中的HTML标签引起的错误 [英] Catching "Failed to load resources" errors caused by HTML tags in a <webview>
问题描述
我正在Chrome应用中加载网页网页浏览。
我有时在控制台中为某些< script>
和获得无法加载资源 < img>
标签。我想抓住这些错误,所以我可以用JavaScript代码对它们采取行动,而不是在控制台中显示消息。
我无法修改我正在加载的HTML ,即使用AJAX加载资源而不是HTML标签不是一个选项。 修复的资源也是不是我正在寻找的 - 我只是想要一些JavaScript代码在某个地方知道什么是丢失,并从那里采取。
我可以在代码中捕获这些错误,而不是在控制台中显示消息?
您可以安装< webview> WebRequest API观察者,并查看每个资源负载的状态。
这样做不能捕获你看到的资源负载失败?
var webview = document.querySelector('webview'); webview.request.onHeadersReceived.addListener(function(details){if(details.statusLine.match(/ ^ HTTP。* 404 /){// some 404 occurred ... window.console.log('Failed url:'+ details.url);} else if ...},{urls:['< all_urls>']});
/ p>
< webview> WebRequest API类似于 Chrome WebRequest API 。
I am loading web pages in Chrome App webviews.
I sometimes get "Failed to load resource" messages in the console for some of the <script>
and <img>
tags. I want to catch these errors so I can act on them in JavaScript code, rather than have messages appear in the console.
I can not modify the HTML that I am loading, i.e., using AJAX to load the resources rather than HTML tags is not an option. "Fixing" the resources is also not what I am looking for - I just want some JavaScript code somewhere to know what is missing and take it from there.
Can I catch these errors in code, rather than having messages appear in the console?
You can install a <webview> WebRequest API observer and see each resource load's status. Does that not catch the resource load failures you're seeing?
var webview = document.querySelector('webview');
webview.request.onHeadersReceived.addListener(function(details) {
if (details.statusLine.match(/^HTTP.*404/) {
// some 404 happened...
window.console.log('Failed url: ' + details.url);
} else if ...
}, {urls: ['<all_urls>']});
The <webview> WebRequest API is similar to the Chrome WebRequest API.
这篇关于捕获“无法加载资源” < webview>中的HTML标签引起的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!