Define Safari App Extension Swift API requirements
See original GitHub issueExpected Behavior
There should be explicit requirements of API that cannot be supported in Safari and that should be accessed via swift.
Interface requirements
We need to address 3 major areas
1. tab methods
executeScript
- signal to execute a javascript file
- this may be tricky as apple wants us to preload all extension scripts now so it may require refactoring the scripts so that they are not executed upon loading or creating variants with this behavior so that they only execute a function when manually triggered
openBackgroundTab
- used for login and authentication
closeTab
- a way to close a tab; after logging in, close the login tab
setToolbarIcon
- a way to update the toolbar icon
- we need this API so we can switch the toolbar icon when the user makes a save, when the user saves to pocket, we need to switch to the red icon
- for dark mode vs light mode based on the user’s system preference
2. tab events
- onTabCreated
- onTabUpdate
- onTabActivated
- onTabRemoved
- onTabReplaced
tab event details
The event should have an object passed with tab details such as:
- tabId
- url
- selected/highlighted/active
- status (loading or completed loading)
3. API calls
- a means of making api calls and receive responses for the following
- save to pocket
- save tags
- fetch recommended tags
- fetch tags
- @nzeltzer to provide an api that accepts a url and an object, for example if I need to make a POST call, I call Nik’s api and provide him a url, parameter objects and xhr method (POST/GET) and he constructs the xhr call based on this, makes the call and returns me the response body and response status
4. Cookies
We need a way to identify cookies set in the browser for any base url. Something similar to chrome.cookies
API https://developer.chrome.com/extensions/cookies
5. Miscellaneous
a) options page - TODO: frontend will handle
-
How will we be able to handle an options page, based on my last discussion with @nzeltzer on this we did not see a way how this could be achieved in Safari 12. Additional research is required for this.
-
~Needs investigation on how to open a new tab to display the options page~
-
~We may display the options in a modal instead of a separate html page~
-
The team has suggested using the mac app or launcher for the options settings
b) onUpdateAvailable
- how to handle updating and reloading the extension
c) Right-click context menu
- Display extension icon and label for “Save to Pocket” which when clicked triggers the extension
d) Keyboard shortcuts
- Triggering the extension via keyboard shortcuts: Ctrl+Shift+P (Windows), Command+Shift+P (Mac)
# Actual Behavior
Extension not working in safari.
# Steps to Reproduce the Problem
N/A
# Specifications
* Version: Save To Pocket v3.0.6.5
* Browser: Safari
* Operating System: Mac OS Mojave 10.14.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
@here Just checking in to let y’all know that I’ve been actively working on the Swift API bridge as outlined in Nelson’s Github issue (https://github.com/Pocket/extension-save-to-pocket/issues/88)
Here’s a brief update on where I’m at:
💚
executeScript
(possible; in process—may need some more guidance once I get a little deeper into it) 💚openBackgroundTab
(done—can pass in an arbitrary url string) 🔶closeTab
(possible)—we can close a tab; it appears that we can close an arbitrary tab; would be useful to know what parameters we want to pass to this method (i.e., do we want to close the active tab, or do we want the ability to close a specific tab?) 🔶setToolbarIcon
(impossible; not clear on why we need this—if it’s for theming on dark/light theme, there are better ways to do this) 🖤tab events
(impossible from the Swift side—there may be Javascript callbacks, but I haven’t investigated yet) 💚API calls
(possible; in progress—I am writing a basic API client that will allow you to pass in a JSON object withurl
,method
,callback
andparameters
fields. The JSON response, HTTP status code, etc will be passed back to thecallback
function).@nelsonomuto This looks doable. What would you like as far as an API is concerned?
Is the ability to pass in an image name sufficient?