Unlike chrome, which provides a special API for events such as window and tab changes, you can still do this with safari extensions.
You just need your nested javascript to set up event listeners for the events you want.
Then, if this information is needed globally or in other parts of the extension, you can pass the information in the messages using the postMessage command.
injected.js:
window.addEventListener("load", loaded, false);
safari.self.tab.dispatchMessage("somethinghappened","load");
source
share