Posts

Post not yet marked as solved
2 Replies
1k Views
I made a Safari Web extension that's supposed to work like this: WHEN: Safari is opening http://example.com/ THEN: The extension opens a page embedded in the extension instead. This is the implementation of background.js: browser.tabs.onUpdated.addListener(async function (tabId) { const tab = await browser.tabs.get(tabId); if (tab.url == "http://example.com/") { const destination = browser.runtime.getURL("embedded-page.html"); browser.tabs.update(tabId, { url: destination }); } }, null); This is the source project: https://www.icloud.com/iclouddrive/042qIjivEoJ0V3qIcLGcytAPA When opening http://www.example.com/ for the first time, it successfully navigates to the embedded page. However, once that navigation is done, the extension no longer works that way unless I re-enable the extension. It's like the listeners are removed by that navigation. This is the video of this issue: https://www.icloud.com/iclouddrive/0f9Yl1jC9eQ8OmgH8vAtEA6Pw Can you replicate this on your Mac? And do you know what's the cause? This happens for a listener of browser.webNavigation.onBeforeNavigate too. Maybe more. On the other hand, when I set a normal page such as https://www.apple.com/ to destination, It always works fine for me. So I'm wondering if this issue is related to the embedded page. FYI, I already reported this issue as FB9967637 on 27th March but no reply from Apple as of now. My environment macOS Monterey 12.3.1 (21E258) Safari 15.4
Posted
by normal.
Last updated
.
Post not yet marked as solved
3 Replies
1.7k Views
I'm now trying to add Drag & Drop feature to my NSTableView which uses NSTableViewDiffableDataSource for its data source. However, I can't implement the methods for Drag & Drop like tableView(:, acceptDrop:, row:, dropOperation:). My code looks like this: swift class MyViewController: NSViewController { private let tableView: NSTableView = {...}() private lazy var dataSource = MyDataSource(tableView: tableView) ... } class MyDataSource: NSTableViewDiffableDataSourceSection, Model { ...     override func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: IndexSet) { ...     } } Since NSTableViewDiffableDataSource implements NSTableViewDataSource protocol which provides Drag & Drop methods, I thought the above overriding method would work but I got this error. Method does not override any method from its superclass What happened? And if this is expected, how can I implement Drag & Drop with NSTableViewDiffableDataSource?
Posted
by normal.
Last updated
.
Post not yet marked as solved
0 Replies
785 Views
I'm trying to present a resizable NSWindow defined like this: let window = NSWindow() window.contentViewController = NSHostingController( rootView: Rectangle().frame(minWidth: 100, minHeight: 100)) window.styleMask.insert([.closable, .resizable]) Generally, I can resize this window but somehow I can NOT when it's presented from Safari app extension (.appex). Did I miss something? Does anyone know what's happening?
Posted
by normal.
Last updated
.
Post not yet marked as solved
1 Replies
736 Views
I'm developing a Safari web extension for macOS that calls SFSafariApplication.dispatchMessage() (Swift) to communicate with background.js and the popup. However, I noticed that the method forcefully switches Safari to foreground. It seems it happens after calling browser.runtime.sendNativeMessage(''); in JavaScript. Is there a way to avoid that behavior? Or perhaps I'm misunderstanding something? This is a sample project and its video (Safari is switched to foreground every 3 seconds.): Sample project: https://www.dropbox.com/s/vs7h128ef1ji34q/ForcefulForegroundIssuePlayground.zip?dl=0 Video: https://www.dropbox.com/s/7pjbh1rihnh068l/Screen%20Recording%202021-12-23%20at%205.42.44%20pm.mov?dl=0 By the way, I already submitted a feedback for this as FB9804951 about 2 weeks ago but no response from Apple so far and I don't know if Apple will take any action for that or not even after the new year so I decided to ask here as well.
Posted
by normal.
Last updated
.
Post marked as solved
1 Replies
837 Views
When the user tries to open a non-existing URL such as https://dsjiksfdakjf.com, Safari shows a built-in error page that displays texts like this: Safari Can’t Find the Server Safari can’t open the page “https://dsjiksfdakjf.com” because Safari can’t find the server “dsjiksfdakjf.com”. Can a Safari extension detect when this happen? Background of question I'd like to allow users to redirect from a broken or censored (HTTP 451) URL to another URL as a fallback, so that my users won't loose what they can still do other than just closing the tab. I've been looking for the solution but so far, no luck. I couldn't find out such functionalities from SFSafariExtensionHandler, SFSafariPage, etc. JavaScript files of extensions are not loaded for that error page either. I even wonder if it actually can't detect and what I can do for now is just to submit the feedback to Apple...
Posted
by normal.
Last updated
.