从文件系统HTML页面向Chrome扩展名发送消息 [英] Sending messages from file system html page to a chrome extension

查看:111
本文介绍了从文件系统HTML页面向Chrome扩展名发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是创建Chrome扩展程序的新手.我要测试将网页中的消息发送到扩展程序,如下所述: https://developer.chrome.com/extensions/messaging#external-webpage .

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.

我只想在文件系统中使用html文件(例如"file:///C:/Users/johng/Documents/TestExtensionCall.html")进行初始测试,但开发人员文档指出您需要在扩展程序清单中包括"externally_connectable"以公开消息传递api,并且url模式必须包含第二级域.

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.

文件系统中的html文件可以用于测试从网页向chrome扩展名发送消息的情况吗?我是否真的需要使用网站上的网页进行测试?

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?

谢谢, 约翰

推荐答案

要测试externally_connectable,您需要 1 可以使用Web服务器.

For testing externally_connectable, you have1 to use a web server.

尽管如此,您仍然可以使用本地开发Web服务器.通常,它的主机名是localhost,但是您可以在DNS主机文件中为其指定别名,例如my.localhost,这样就可以满足Chrome的要求.

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.

1 据我所知

这篇关于从文件系统HTML页面向Chrome扩展名发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆