gpt4 book ai didi

javascript - Safari 扩展多次运行注入(inject)的 javascript

转载 作者:搜寻专家 更新时间:2023-11-01 05:26:47 25 4
gpt4 key购买 nike

我已经从 Apple Developer 网站上的以下示例中复制了代码。

https://developer.apple.com/library/content/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW1

当我运行扩展时,它运行正常,除了注入(inject)的脚本运行了 3 次导致输出被写入 console.log 3 次。我还在 doBigCalc 函数中放置了一个警报,它打开了 3 个警报。

为什么会发生这种情况/是否应该发生这种情况?

最佳答案

您没有谈到您的实现,但您的代码可能不是问题所在。关键是了解加载了注入(inject)的脚本....来自injected script documentation :

Scripts are injected into the top-level page and any children with HTML sources, such as iframes. Do not assume that there is only one instance of your script per browser tab.

关于javascript - Safari 扩展多次运行注入(inject)的 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3190759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com