Skip to content

Commit

Permalink
Load notification polyfill before user JS
Browse files Browse the repository at this point in the history
  • Loading branch information
kofigumbs committed Jul 22, 2023
1 parent db0b46d commit 39daea1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Sources/MultiRuntime/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ struct TabView: View {
let delegate: TabViewDelegate
let onPresent: (NSWindow) -> Void

var notificationPolyfill: [WKUserScript] {
guard let url = SettingsView.url(forResource: "notification.js"),
let js = try? String(contentsOf: url) else {
return []
}
return [WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false)]
}

var customCss: [WKUserScript] {
delegate.tab.customCss.compactMap({ try? Data(contentsOf: $0).base64EncodedString() }).map { css in
WKUserScript(
Expand All @@ -32,14 +40,6 @@ struct TabView: View {
}
}

var notificationPolyfill: [WKUserScript] {
guard let url = SettingsView.url(forResource: "notification.js"),
let js = try? String(contentsOf: url) else {
return []
}
return [WKUserScript(source: js, injectionTime: .atDocumentStart, forMainFrameOnly: false)]
}

var cookies: [HTTPCookie] {
delegate.tab.customCookies.compactMap { cookie in
let properties: [HTTPCookiePropertyKey: Any?] = [
Expand Down Expand Up @@ -70,7 +70,7 @@ struct TabView: View {
userAgent: delegate.tab.userAgent,
ui: delegate.appDelegate,
navigation: delegate,
scripts: customCss + customJs + notificationPolyfill,
scripts: notificationPolyfill + customCss + customJs,
cookies: cookies,
handlers: [
"notificationRequest": notificationRequest,
Expand Down

0 comments on commit 39daea1

Please sign in to comment.