@@ -1958,6 +1958,45 @@ - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
19581958 WKUserScript *userScript = [[WKUserScript alloc ] initWithSource: html5HistoryAPIShimSource injectionTime: WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly: YES ];
19591959 [wkWebViewConfig.userContentController addUserScript: userScript];
19601960
1961+ NSString *serviceWorkerPreventCrashesSource = @" (function() {\n "
1962+ " if (!('serviceWorker' in navigator)) {\n "
1963+ " Object.defineProperty(navigator, 'serviceWorker', {\n "
1964+ " value: {\n "
1965+ " register: function(scriptURL, options) {\n "
1966+ " return Promise.resolve({\n "
1967+ " installing: null,\n "
1968+ " waiting: null,\n "
1969+ " active: {\n "
1970+ " scriptURL: scriptURL,\n "
1971+ " state: 'activated'\n "
1972+ " },\n "
1973+ " scope: options?.scope || '/',\n "
1974+ " update: () => Promise.resolve(),\n "
1975+ " unregister: () => Promise.resolve(true)\n "
1976+ " });\n "
1977+ " },\n "
1978+ " getRegistration: () => Promise.resolve(null),\n "
1979+ " getRegistrations: () => Promise.resolve([]),\n "
1980+ " ready: Promise.resolve({\n "
1981+ " installing: null,\n "
1982+ " waiting: null,\n "
1983+ " active: null,\n "
1984+ " scope: '/'\n "
1985+ " }),\n "
1986+ " controller: null,\n "
1987+ " addEventListener() {},\n "
1988+ " removeEventListener() {}\n "
1989+ " },\n "
1990+ " configurable: true\n "
1991+ " });\n "
1992+ " }\n "
1993+ " })();" ;
1994+ WKUserScript *serviceWorkerPreventCrashesScript = [[WKUserScript alloc ]
1995+ initWithSource: serviceWorkerPreventCrashesSource
1996+ injectionTime: WKUserScriptInjectionTimeAtDocumentStart
1997+ forMainFrameOnly: NO ];
1998+ [wkWebViewConfig.userContentController addUserScript: serviceWorkerPreventCrashesScript];
1999+
19612000 if (_sharedCookiesEnabled) {
19622001 // More info to sending cookies with WKWebView
19632002 // https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview/26577303#26577303
0 commit comments