Note that there are some explanatory texts on larger screens.

plurals
  1. POSafari extension options pages with access to background page
    primarykey
    data
    text
    <p>I'm developing a cross-platform browser extension, and have based all my code on the Chrome-way of doing this. I have counted on that the background page will be accessible from the options page, which in Safari extensions turns out to be not possible (since there is no such thing as an options-page). You can <em>only</em> access <code>safari.extension.globalPage.contentWindow</code> from within the extension popup, and the background page itself.</p> <p>Now, I have an options page, which is an html-page within the extension bundle, and so far I haven't found a way for Safari to give it extension "rights". The closest I have come is adding a content script that's only added on the options page. This seems a bit silly, since the html page itself is in the extension bundle?!</p> <p>Others have suggested using asynchronous ping-pong style <code>message</code> event handlers, and even the <code>canLoad</code>-mechanism (which is "only" able to run in a <code>beforeload</code>-event). I have been able to hack the <code>canLoad</code>-mechanism for synchronous messaging by forging the <code>BeforeLoadEvent</code>:</p> <pre><code>// Content script (run from anywhere) var result = safari.self.tab.canLoad(new BeforeLoadEvent, "data") -&gt; "return value" // Background page safari.application.addEventListener('message', function(e) { if ( e.name === "canLoad" ) e.message = "return value"; }, true); </code></pre> <p>It's a hack, but it works. However, I am crippled by the message transport serialization, since I need to be able access methods and data on my objects from the background page. Is there anyway around this?</p> <p>Possible ways that might work but I don't know if possible:</p> <ul> <li>Access options-page <code>window</code>-object from backgrounds page. Is that possible?</li> <li>Message passing, need to bypass message serialization</li> <li>Any shared/global object that I can attach objects to and fetch from the options page?</li> <li>Make Safari run the options.html page from outside the content-script sandbox? It works in Chrome since they are both within the extension-bundle. It's quite annoying that safari doesn't do this too.</li> <li>Run the options-page from within the popup. This is promising, but it crashes safari (which is very promising!). However, from the looks of it it's just something to do with a CSS animation in my options.html page. The biggest issue is that it has to be able to open an OAuth2 popup, but thanks to being able to programmatically open the popover, it might be a non-issue. However, this option is the most realistic, but I would rather have it open in a new tab.</li> </ul> <p>Any suggestions and hackish workarounds would really help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload