谷歌浏览器扩展开发,怎么样才能调用网页的JS函数

谷歌浏览器扩展开发,怎么样才能调用网页的JS函数,第1张

我摘抄了一段官方文档中关于这一点的解释:

Execution environment

Content scripts execute in a special environment called an isolated world. They have access to the DOM of the page they are injected into, but not to any JavaScript variables or functions created by the page. It looks to each content script as if there is no other JavaScript executing on the page it is running on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts.

摘自:网页链接

其中提到了 content scripot 的执行环境页面原来的直用环境其实并不是同一个环境,而是一个隔离的环境,他们相互纤陪之间并不影响。也就说你访问不了原来页面里的变量,原来的页面也访问不了你新创建的变量。

但是,我们可以枯备通过另外的方法与原页面通信,可以参考上文官方链接中 Communication with the embedding page 这节内容。

另外,还有一种办法,content script 执行在隔离环境,但 content script 可以通过 js 动态插入另一个没竖毁 <script>,这个script 并不受限制,从而曲线实现。

各种方案略有差异,还需根据各自的需求来选择。

一加手机的Google服务框架的外部调用启动在系统设置中,用户可以在系统设置中找到“应用程序和服务”,在该菜单中,用户可以找到“Google服务框架”,点击进入后,可以看到Google服务框架的各种设置,包敏陪括启动、停止服务、重置服务圆橡等,用户可以在这里启动外部调橘拿旁用Google服务框架。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12225108.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存