Posts

Post not yet marked as solved
1 Replies
269 Views
Hello, Is it possible to take a screenshot of a non-active tab? Firefox supports this via captureTab (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureTab) With Safari App extensions that was possible via getScreenshotOfVisibleArea which doesn't seem to work with Safari extensions.
Posted
by bruno.cm.
Last updated
.
Post marked as solved
2 Replies
451 Views
Hello, According to MDN, Safari v15.4+ should fully support declarativeNetRequest.Redirect, including regexSubstitution, but when I use it in a rule I get this: Rule: EXT_PAGE = '/hello.html'; RULES = [{ id: 1, action: { type: 'redirect', redirect: { regexSubstitution: EXT_PAGE + '#\\0' }, }, condition: { requestDomains: ['example.com'], regexFilter: '^.+$', resourceTypes: ['main_frame', 'sub_frame'], }, }]; browser.declarativeNetRequest.updateDynamicRules({ removeRuleIds: RULES.map(r => r.id), addRules: RULES, }); Error: Invalid call to declarativeNetRequest.updateDynamicRules(). Error with rule at index 0: Rule with id 1 is invalid. redirect is missing either a url, extensionPath, or transform key.
Posted
by bruno.cm.
Last updated
.
Post marked as solved
7 Replies
1.4k Views
FB7597364 (attached video there) Hello, I have filled a radar but I'm wondering if I am misunderstanding the following (Safari TP 104+): Make the extension open a new tab with the baseURI and a parameter, eg.: safari-extension://2CB967-22BA-44F3-B604-72611F/aafefbf/test.html?title=Apple&color=red Here's the code I'm using: SFSafariApplication.getActiveWindow { activeWindow in 						SFSafariExtension.getBaseURI { baseURI in 								guard let baseURI = baseURI else { return } 								var urlComponents = URLComponents(string: baseURI.appendingPathComponent("test.html").absoluteString); 							 								urlComponents?.queryItems = [ 									 URLQueryItem(name: "title", value: "Apple"), 									 URLQueryItem(name: "color", value: "red"), 								]; 								activeWindow?.openTab(with: (urlComponents?.url)!, makeActiveIfPossible: true, completionHandler: {_ in }); 						} 				} 2. Wait for the page to load 3. Quit Safari 4. Open Safari Expected: Safari updates the baseURL of that tab and keeps the query parameters, eg: safari-extension://11111-new-baseURI-44F3-B604-72611F/o213s/test.html?title=Apple&color=red Actual: Safari updates the baseURL of that tab and strips the query parameters, eg: safari-extension://11111-new-baseURI-44F3-B604-72611F/o213s/test.html
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
1 Replies
454 Views
Hello, How can I change the commands originally set in the manifest? Is there a special internal url like in chrome since browser.commands.update does not seem to exist in Safari. Thank you
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
0 Replies
539 Views
Hello, Is it possible to take a screenshot of a non-active tab? Firefox supports this via captureTab (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/captureTab) With Safari App extensions that was possible via getScreenshotOfVisibleArea which doesn't seem to work with Safari extensions.
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
0 Replies
424 Views
Feedback ID: FB8176693 Hello, I have reported this before, but just noticed the behaviour is different in web extensions. Have an web extension create a new tab to open an HTML page inside the extension resources: browser.tabs.create({'url': browser.runtime.getURL("test.html") + '?p1=test&p2=test2' }); Now the equivalent in an app extension: SFSafariApplication.getActiveWindow { activeWindow in SFSafariExtension.getBaseURI { baseURI in guard let baseURI = baseURI else { return } var urlComponents = URLComponents(string: baseURI.appendingPathComponent("test.html").absoluteString); urlComponents?.queryItems = [ URLQueryItem(name: "p1", value: "test"), URLQueryItem(name: "p2", value: "test2"), ]; activeWindow?.openTab(with: (urlComponents?.url)!, makeActiveIfPossible: true, completionHandler: {_ in }); } } After the tab is created notice its URL, eg.: safari-extension://2CB967-22BA-44F3-B604-72611F/aafefbf/test.html?p1=test&p2=test2 Now, restart Safari. Expected: Restored tab shows the same url (minus the baseURL which has been updated) Actual: The tab created by the Safari app extension shows the updated baseURI without any parameters. Eg.: safari-extension://11111-new-baseURI-44F3-B604-72611F/o213s/test.html - The tab created by the Safari web extension shows the full url as expected Considering this is affecting a great number of my users and renders the extension pretty useless, I am wondering if there are any realistic plans to fix this? Moving to web extension might be very problematic as the extension requires access to all pages the user accesses and since most users are not very tech savvy it will be quite hard to guide them through the new permission prompts. Thank you
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
1 Replies
972 Views
Here's my manifest.json: {   "manifest_version": 2,   "default_locale": "en",   "name": "MSG_extension_name",   "description": "MSG_extension_description",   "version": "1.0",   "icons": {     "48": "images/icon-48.png",     "96": "images/icon-96.png",     "128": "images/icon-128.png",     "256": "images/icon-256.png",     "512": "images/icon-512.png"   },   "background": {     "scripts": [ "background.js" ]   },   "content_scripts": [{     "js": [ "content.js" ],     "matches": [ "*://example.com/*" ]   }],   "browser_action": {     "default_popup": "popup.html",     "default_icon": {       "16": "images/toolbar-icon-16.png",       "19": "images/toolbar-icon-19.png",       "32": "images/toolbar-icon-32.png",       "38": "images/toolbar-icon-38.png"     }   },   "permissions": ["<all_urls>", "tabs"] } On my background.js, I have this: browser.tabs.onCreated.addListener(tab => {   console.log("onCreated", tab) }) browser.tabs.onCreated.addListener((tabId, changeInfo, tab) => {   console.log("onUpdated", tabId, changeInfo, tab) }) When I open a new tab I see this in the background log: "onCreated": { &#9;"id": 7, &#9;"index": 1, &#9;"active": true, &#9;"width": 938, &#9;"audible": false, &#9;"url": "", &#9;"mutedInfo": { &#9;&#9;"muted": false &#9;}, &#9;"windowId": 2, &#9;"title": "", &#9;"pendingUrl": "", &#9;"incognito": true, &#9;"pinned": false, &#9;"height": 1027, &#9;"highlighted": true, &#9;"status": "complete" } "onUpdated": { &#9;"id": 7, &#9;"index": 1, &#9;"active": true, &#9;"width": 938, &#9;"audible": false, &#9;"url": "", &#9;"mutedInfo": { &#9;&#9;"muted": false &#9;}, &#9;"windowId": 2, &#9;"title": "", &#9;"pendingUrl": "", &#9;"incognito": true, &#9;"pinned": false, &#9;"height": 1027, &#9;"highlighted": true, &#9;"status": "complete" } Problem 1 Why are the title, url and pendingUrl empty if I have the permission set for all urls and the user accepted it? Problem 2 Safari internal pages url, eg.: "about:blank" are not included in browser.tabs.query, eg.: browser.tabs.query({}, el => { console.log(el)})
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
0 Replies
289 Views
<please delete>
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
1 Replies
450 Views
Hello, I have an extension that will do some processing on a website chosen by the user and then it will show a report in an extension's internal page, eg.: safari-extension://2CB967-22BA-44F3-B604-72611F/aafefbf/report.html?domain=wikipedia.org&tm=1600000000 There are 2 problems with this approach: If the user closes Safari, the next time they will open it (and Safari is set to open the previous session tabs), the extension's internal page will have its parameters stripped, it will open like this: safari-extension://1KP84U-KO31-00L1-M133-032P11/ksleif/report.html Notice the lack of query parameters. The extension's baseURI change is expected and is not an issue since Safari 14 updates the baseURI of the tab with the new baseURI of the extension If the user tries to open that report url in an iPhone or iPad, the page will fail to load as it is an extension's internal page. For point 1. I believe this is a bug? I've filled a report: FB8176693 For point 2. I have tried the following: Instead of using an extension's internal page, I encoded the full report's HTML and display in in data URI, eg.: data:text/html;charset=UTF-8,<span onclick=%22alert(%27test%27);%22>Hello</span> But iOS will not show any tabs from iCloud open that use the data protocol(?) iOS app that register's the safari-extension:// protocol. But I'm sure that would never get approved I guess it's also possible to open the report in my own website, but that would be a major privacy issue. Something that neither me nor my users would not feel comfortable with. Are there any other options? I feel like I hit a wall
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
1 Replies
416 Views
Hello, I have a Safari App extension I would like to make it accept keyboard shortcuts to trigger certain actions. Safari web extensions support this via the Commands API (per mozilla docs). Is it possible to have some sort of hybrid extension and use this Commands API somehow in the Safari App extension? Related feedback ID I filled a couple of months ago: FB7597545 Thank you
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
9 Replies
1.9k Views
Hello,I've filled a radar about this issue: FB7597364 but I'm wondering if anyone has a reliable workaround for this issue.I have made a Safari app extension which allows users to suspend tabs. Unfortunately, because the baseURI changes each time Safari starts the user sees a "Cannot load page" error in the tabs that were suspended in the previous session, see a suspended page is hosted by the extension it self.Steps to reproduce:- Extension opens a new tab with the url, eg: safari-extension://AAAAAAA-0000-1111-2222-A0A0A0A0/7075e8a3/suspended.html- User restarts Safari- The tab shows "Page cannot be loaded" beacause the baseURI changed, since, as far as I know, it's not possible to make the baseURI unachangeable like on other browsers.My temporary workaround (which fails sometimes) is to, when the extension first loads in that session, iterate all tabs and look for urls that match the suspended pattern:override func validateToolbarItem(in window: SFSafariWindow, validationHandler: @escaping ((Bool, String) -&gt; Void)) { // This is called when Safari's state changed in some way that would require the extension's toolbar item to be validated again. if (!SafariExtensionHandler.safariFirstLoad) { // static var SafariExtensionHandler.safariFirstLoad = true; print("loaded") DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { SFSafariApplication.getActiveWindow { (activeWindow) in activeWindow?.getActiveTab { (activeTab) in SFSafariExtension.getBaseURI { baseURI in guard let baseURI = baseURI else { return }; SFSafariApplication.getAllWindows { windows in for window:SFSafariWindow in windows { window.getAllTabs { tabs in var i = 1; for tab:SFSafariTab in tabs { tab.getActivePage(completionHandler: { page in page?.getPropertiesWithCompletionHandler( { properties in if (properties?.url != nil) { let tabUrl: URL = (properties?.url)!; i = i+1; if (tabUrl.scheme == "safari-extension" &amp;&amp; tabUrl.path.hasSuffix("suspended.html") &amp;&amp; !tabUrl.absoluteString.starts(with: baseURI.absoluteString)) { tab.activate { tab.navigate(to: URL(string: "\(baseURI.absoluteString)suspended.html?\(tabUrl.query!)")!); if (i &gt;= tabs.count) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { activeTab?.activate(completionHandler: { }); } } } } } }); }); } } } } } } } } } validationHandler(true, ""); }Unfortunately this does not work 100% of the times as page?.getPropertiesWithCompletionHandler returns nil sometimes.Any ideas on what else I could do?
Posted
by bruno.cm.
Last updated
.
Post not yet marked as solved
0 Replies
711 Views
Hello,Chrome and Firefox tab object contains a property called audible which is either true/false depending if that particular tab has produced sound over the past couple of seconds.Is there such thing in Safari's App extension API? I see the audio icon in the tab but I can't find any docs about it.Javascript based detection via Injected scripts is not that reliable.Thank you
Posted
by bruno.cm.
Last updated
.