问题
I'm new to creating chrome extensions. I want to test sending messages from a web page to an extension as described here: https://developer.chrome.com/extensions/messaging#external-webpage.
I'd like to just use an html file in my file system, like "file:///C:/Users/johng/Documents/TestExtensionCall.html", to do the initial testing but the developer documentation indicates that you need to include "externally_connectable" in your extension manifest to expose the messaging api and the url pattern must include a second-level domain.
Can an html file from the file system be used to test sending messages from a web page to a chrome extension? Do I actually need to use a web page from a web site to do the testing?
Thanks, John
回答1:
For testing externally_connectable
, you have1 to use a web server.
Though, you can still use a local development web server. Normally, it would have a localhost
hostname, but you can specify an alias for it in your DNS hosts file, say, my.localhost
, and it would satisfy Chrome's requirements.
See here for more information about the hosts file.
1To the best of my knowledge
来源:https://stackoverflow.com/questions/24835565/sending-messages-from-file-system-html-page-to-a-chrome-extension