question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Define Safari App Extension Swift API requirements

See original GitHub issue

Expected 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

  1. onTabCreated
  2. onTabUpdate
  3. onTabActivated
  4. onTabRemoved
  5. onTabReplaced

tab event details

The event should have an object passed with tab details such as:

  1. tabId
  2. url
  3. selected/highlighted/active
  4. status (loading or completed loading)

3. API calls

  • a means of making api calls and receive responses for the following
  1. save to pocket
  2. save tags
  3. fetch recommended tags
  4. 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:closed
  • Created 4 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
nzeltzercommented, Jul 24, 2019

@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 with url, method, callback and parameters fields. The JSON response, HTTP status code, etc will be passed back to the callback function).

0reactions
nzeltzercommented, Aug 15, 2019

@nzeltzer that’s only one of the use cases, we also 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

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Safari app extensions | Apple Developer Documentation
Safari app extensions use a combination of JavaScript, CSS, and native code written in Objective-C or Swift. Because you build Safari app extensions...
Read more >
Creating a Safari App Extension - Inside Stylight
Project Targets. The project for a Safari App Extensions contains at least two targets: The native macOS application which is the container for ......
Read more >
How to Build a Safari App Extension in iOS 15 - Ben Edelstein
A detailed guide to developing Safari App Extensions on iOS, using React, TypeScript, and Xcode.
Read more >
Get active tab from safari app in an extension? - Stack Overflow
If you are trying to build an app extension, you have the wrong boilerplate. When making the new target you should have selected...
Read more >
Creating a simple Safari App Extension in 10 minutes
Let's start by creating a new Xcode project. Open Xcode, click on “Create a new Xcode project” and then select “Safari Extension App”...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found