5

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)

ckn
  • 63
  • 1
  • 7
  • 5
    [As explained by the API developer in comment 29](https://crbug.com/835287#c28) this is an intended change as of Chrome 66: chrome.runtime is exposed by default now only on HTTPS sites, not on HTTP. To have it on HTTP you need to install an extension that has that URL matched in its [externally_connectable](https://developer.chrome.com/extensions/manifest/externally_connectable). – wOxxOm Nov 16 '18 at 17:57
  • So, at least 1 of the extensions installed needs to have [externally_connectable](https://developer.chrome.com/extensions/manifest/externally_connectable) matching with the URL that is trying to read chrome.runtime, so that would avoid chrome.runtime undefined for HTTP sites. – ckn Nov 16 '18 at 20:12

0 Answers0