i'm writing a Safari App Extension in Objective C. I use a script.js for the content script. (The entire script.js follows the end of this question).
The procedure document.addEvent.... works every time. From time to time I send a string url to safari.self.addEvent... When I tell it to load simple websites like the home pages for Google and Hacker News, there is no problem. I can load them again and again. However after I have loaded a complicated website like Google Translate, the procedure safari.self.addEvent...often does not respond at all. I may need to load a few more websites for this problem to occur.
Sometimes when I manually load a website via the Safari menu, safari.self.addEvent.. will work for a time or two. Evidently, complicated websites can leave Safari in a confused state. Do you have any suggestions?
Error messages associated with loading Google Translate]1 The problem occurs after these messages when I tell safari.self.addEvent to load another file.
document.addEventListener('DOMContentLoaded', function(event) {
console.log('DOM content loaded');
safari.extension.dispatchMessage("Hello World!");
});
safari.self.addEventListener('message', function(event) {
console.log('in safari.self.addEventListner');
if (event.name === "Load URL") {
var urlString = event.message.urlString;
console.log('Received Load URL message from extension handler', urlString);
window.location.href = urlString;
console.log('Did call window.location.href = urlString');
}
});