I also tried to find a way to "execute" or "attach" the script during installation. This is possible in Chrome and Firefox, without having to reload the page. Unfortunately, in Safari I did not find a way to do this without reloading the page, and let the normal addContentScript handlers take care of the script input.
To reload all Safari tabs immediately after installing the extension:
function reloadTabs() {
var browserWindows = safari.application.browserWindows;
for (var i = 0; i < browserWindows.length; i++) {
var tabs = browserWindows[i].tabs;
for (var j = 0; j < tabs.length; j++) {
tabs[j].url = tabs[j].url;
}
}
}
function onInstall() {
reloadTabs();
}
var firstRun = localStorage['extensionHasPreviouslyRun'] === undefined ||
!JSON.parse(localStorage['extensionHasPreviouslyRun']);
if (firstRun) {
onInstall();
localStorage['extensionHasPreviouslyRun'] = JSON.stringify(true);
}
source
share