Why is chrome.runtime undefined when opening website using http and not https?

Viewed 2045

I have a very simple html file with the following:

mypage.html

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

When I use this html file in a web server with http, then chrome.runtime is undefined. Example: http://localhost:8080/myapp/mypage.html

But, if I use this html file in a web server with https, then chrome.runtime is NOT undefined. Example: https://localhost:8080/myapp/mypage.html

Background: I need to use this to validate if a chrome extension is installed or not. But having chrome.runtime undefined I think that would not be possible.

Also, I tried to follow some other similar questions, but I couldn't get it work when opening it through http and not https.

Why is chrome.runtime undefined in the content script? Why is chrome.runtime undefined?

Chrome: Version 70.0.3538.102 (Official Build) (64-bit)

0 Answers
Related