admin管理员组文章数量:1321449
I have copied the code from the following example on the Apple Developer site.
.html#//apple_ref/doc/uid/TP40009977-CH14-SW1
When I run the extension, it runs normally except the injected script is run 3 times causing the output to be written to console.log 3 times. I also put a alert in the doBigCalc function and it opened 3 alerts.
Why is this happening/is it supposed to happen?
I have copied the code from the following example on the Apple Developer site.
https://developer.apple./library/content/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW1
When I run the extension, it runs normally except the injected script is run 3 times causing the output to be written to console.log 3 times. I also put a alert in the doBigCalc function and it opened 3 alerts.
Why is this happening/is it supposed to happen?
Share Improve this question edited May 5, 2018 at 13:42 Cœur 38.8k26 gold badges205 silver badges277 bronze badges asked Jul 6, 2010 at 22:45 Craig SiemensCraig Siemens 13.3k1 gold badge35 silver badges54 bronze badges2 Answers
Reset to default 8You don't speak to your implementation, but it could be that your code isn't the problem. The key is understanding that an injected script is loaded .... From the 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.
The documentation mentions that you can dispatch messages using event handlers on three different levels:
safari.application.activeBrowserWindow.activeTab.addEventListener("message", waitForMessage, false);
safari.application.activeBrowserWindow.addEventListener("message", waitForMessage, false);
safari.application.addEventListener("message", waitForMessage, false);
But you should choose one of the the three. You aren't attaching event listeners to all three are you? If you are, you'll get it run three times for sure.
本文标签: Safari extension running injected javascript multiple timesStack Overflow
版权声明:本文标题:Safari extension running injected javascript multiple times - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742100061a2420761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论