Post

Replies

Boosts

Views

Activity

Spawning a service worker in a safari web extension in the background
new Worker(browser.runtime.getURL('source/worker.js')) throws an error: Error: This script should only be loaded in a browser extension. I have a hefty background processing operation that I need to pass off to a web worker, but the script I try to execute causes this error. Is there a standard way of spawning a web worker in a background script for a safari web extension?
0
0
828
Feb ’22
UIPasteboard copying string to clipboard is not working on iOS 15 device
I am currently developing a safari web extension on iOS. The following piece of code is executed in the native application when the extension sends a message to the native app using browser.runtime.sendNativeMessage.    func beginRequest(with context: NSExtensionContext) {     let item = context.inputItems[0] as! NSExtensionItem     let message = item.userInfo?[SFExtensionMessageKey]     os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg) //    Message should follow format of: //    { //     type: "Message type", //     payload: "Message Payload" //    } //    In the future we may want to parse the payload differently, but for now it is a string     guard let response = message as? [String : AnyObject] else {       return     }     guard let type = response["type"] as? String else {       return     }     guard let payload = response["payload"] as? String else {       return     }           let res = NSExtensionItem()           if type == "COPY" {       let itemToCopy = [payload]       let pasteboard = UIPasteboard.general       pasteboard.strings = itemToCopy       res.userInfo = [ SFExtensionMessageKey: [ "res": true ] ]     }     context.completeRequest(returningItems: [res], completionHandler: nil) The code works flawlessly in the iOS 15 simulator, however it does not work on the actual device. ( iPod Touch 7th Generation running iOS 15 beta 2 ) There are no errors, it behaves as if it was working as expected. Any help would be greatly appreciated.
4
0
1.6k
Jul ’21
Programmatically open popup in Safari Web Extension
I have a Safari web extension that needs the ability to open the popup when the user interacts with a modal coming from the content script. There is a native message handler that comes with the safari web extension when you first create it: import SafariServices import os.log class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { func beginRequest(with context: NSExtensionContext) { let item = context.inputItems[0] as! NSExtensionItem let message = item.userInfo?[SFExtensionMessageKey] os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@", message as! CVarArg) let response = NSExtensionItem() response.userInfo = [ SFExtensionMessageKey: [ "Response to": message ] ] print("hit") context.completeRequest(returningItems: [response], completionHandler: nil) } } I have the permissions to send a native message, I've seen some examples online where you can access the SFSafariApplication module from SafariServices and open the popover. But I can't seem to access SFSafariApplication in this module.
1
0
1.1k
Jul ’21