Safari extension launched javascript several times

So, I copied the code from the following example on the Apple Developer website.

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

When I run the extension, it works fine, except that the script I entered runs 3 times, forcing the output to write to console.log 3 times. I also added a warning to the doBigCalc function and opened 3 warnings.

Why is this happening / supposed to happen?

+3
source share
2 answers

, , . , script.... script:

HTML, iframes. , script .

+5

, :

safari.application.activeBrowserWindow.activeTab.addEventListener("message", waitForMessage, false);

safari.application.activeBrowserWindow.addEventListener("message", waitForMessage, false);

safari.application.addEventListener("message", waitForMessage, false);

. , ? , .

+1

Source: https://habr.com/ru/post/1753431/


All Articles