为什么使用 http 而不是 https 打开网站时 chrome.runtime 未定义?

2024-02-03

我有一个非常简单的 html 文件,其中包含以下内容:

我的页面.html

<html>
<head>
	<script language="javascript">
		alert(chrome.runtime);
	</script>
</head>
<body>
	<p>chrome.runtime test</p>
</body>
</html>

当我在带有 http 的 Web 服务器中使用这个 html 文件时,chrome.runtime 是未定义的。例子:http://localhost:8080/myapp/mypage.html http://localhost:8080/myapp/mypage.html

但是,如果我在带有 https 的 Web 服务器中使用此 html 文件,则 chrome.runtime 不是未定义的。例子:https://localhost:8080/myapp/mypage.html https://localhost:8080/myapp/mypage.html

背景:我需要用它来验证是否安装了 chrome 扩展。但如果 chrome.runtime 未定义,我认为这是不可能的。

另外,我尝试遵循其他一些类似的问题,但通过 http 而不是 https 打开它时我无法使其工作。

为什么内容脚本中 chrome.runtime 未定义? https://stackoverflow.com/questions/44234623/why-is-chrome-runtime-undefined-in-the-content-script 为什么 chrome.runtime 未定义? https://stackoverflow.com/questions/27207129/why-is-chrome-runtime-undefined?lq=1

Chrome:版本 70.0.3538.102(官方版本)(64 位)


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么使用 http 而不是 https 打开网站时 chrome.runtime 未定义? 的相关文章

随机推荐