Safari Extension Questions

前端 未结 4 1183
萌比男神i
萌比男神i 2021-02-05 17:43

I\'m in the process of building my first Safari extension--a very simple one--but I\'ve run into a couple of problems. The extension boils down to a single, injected script that

4条回答
  •  孤城傲影
    2021-02-05 18:37

    It took me several days, but I think I found a workable solution using the canLoad() messaging method. My injection script retrieves settings by calling the global HTML page like this:

    settings = safari.self.tab.canLoad( event );
    

    My global HTML file, in turn, returns those settings as:

    settings = {
      'setting1': safari.extension.settings.getItem( 'setting1' )
    }
    
    msgEvent.message = settings;
    

    It's still a bit more "hacky" than I'd like. I can't seem to simply return the settings object itself, so I have to compile a new object by retrieving each setting manually. Not ideal, but it does seem to be effective.

提交回复
热议问题