我最近在 Chrome 的 console.log 中注意到了这一行,这让我觉得我在以编程方式启动 mailto:
链接时做错了什么。
该行似乎是从位于 https://chromium.googlesource.com/chromium/src/+/master/chrome/browser/external_protocol/external_protocol_handler.cc 的 external_protocol_handler.cc
文件的 Chromium 源代码中调用的
而触发控制台语句的具体代码是:
web_contents->GetMainFrame()->AddMessageToConsole(
blink::mojom::ConsoleMessageLevel::kInfo,
"Launched external handler for '" + url.possibly_invalid_spec() + "'.");
函数名称 url.possibly_invalid_spec()
让我产生疑问。
我所做的就是使用 JavaScript 打开来自 https://
网站的 mailto:
链接(如果与它有任何关系的话)window.location.href = 'mailto:me@website.com';
有人听说过这个吗?是新的吗?
最佳答案
查看git blame ,我们看到 Eric Lawrence 于 2020 年 6 月 24 日将记录器添加为 the fix 的一部分对于 bug 1096610,解释如下:
Log external handler invocations to the console.
Previously, failing to invoke an external protocol handler ('foo://bar') would fail silently if the protocol was not registered or if the user gesture requirement was not met. This limitation made it difficult for web developers to troubleshoot such situations. This CL emits errors to the Developer Tools console when the protocol handler is not registered, is forbidden, or is temporarily blocked pending a user-gesture. Similarly, if an external handler is launched, an informational log entry is added.
考虑到这一点,可以得出结论,在 DevTools 控制台中使用它是可以的,因为它只是一个通知,表明浏览器将尝试处理与 http/https
以外的外部协议(protocol)的链接(例如,mailto
、ftp
等)。
关于javascript - 带有 mailto 链接的 Chrome "Launched External Handler"控制台语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64232834/