4

I am trying to allow the user to configure my safari extension through a HTML preference page (as many Safari extensions do). I open this page from a javascript call inside my global html file:

var newTab = safari.application.activeBrowserWindow.openTab();
newTab.url = safari.extension.baseURI + "settings/settings.html";

What I can NOT manage to do is write anything from this settings.html into the actual Safari extension settings or access the global page.

safari.extension.settings.MY_SETTINGS = settingsData;
safari.extension.globalPage

Both of these calls result in exceptions and the objects appear undefined.

I then also tried to send messages, but never seem to receive them in the global space, where I thought I could then again access the settings.

safari.self.tab.dispatchMessage("store_settings", settingsData); //settings javascript

These message are not received by my event listener.

safari.self.addEventListener("message", process_messages, false); //GLOBAL javascript

Any idea why I can not access the extension settings? Do I need to initialise something for my settings.html to be able to access the extension settings?

PS: I have seen a similar approach working inside the ClickToPlugin Safari extension - so it should be possible, but I can't get it to work :(

Chris
  • 3,245
  • 4
  • 29
  • 53

2 Answers2

1

In the global script, try safari.application.addEventListener.

chulster
  • 2,809
  • 15
  • 14
1

If your html page is part of your extension then your settings.js script file will have access to safari.extension.globalPage. This object points to the window of your global.html.

From there you can call any object in that context. Debugging this however is a pain to say the least. Good luck :-)

dimitrirostavo
  • 318
  • 1
  • 13