@capgo/capacitor-webview-crash 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class WebViewCrashWeb extends WebPlugin {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.dispatchedPendingEvents = new Set();
6
+ }
7
+ async getPendingCrashInfo() {
8
+ return { value: this.readPendingCrashInfo() };
9
+ }
10
+ async clearPendingCrashInfo() {
11
+ this.removePendingCrashInfo();
12
+ this.dispatchedPendingEvents.clear();
13
+ }
14
+ async simulateCrashRecovery() {
15
+ const value = this.buildCrashInfo();
16
+ this.writePendingCrashInfo(value);
17
+ this.dispatchedPendingEvents.clear();
18
+ this.flushPendingCrashEvent();
19
+ this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);
20
+ return { value };
21
+ }
22
+ async restartWebView() {
23
+ const value = this.buildCrashInfo('manualRestart');
24
+ this.writePendingCrashInfo(value);
25
+ this.dispatchedPendingEvents.clear();
26
+ this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);
27
+ return { value };
28
+ }
29
+ async addListener(eventName, listenerFunc) {
30
+ const handle = await super.addListener(eventName, listenerFunc);
31
+ if (eventName === WebViewCrashWeb.crashEventName || eventName === WebViewCrashWeb.restartEventName) {
32
+ this.flushPendingCrashEvent(eventName);
33
+ }
34
+ return handle;
35
+ }
36
+ flushPendingCrashEvent(eventName = WebViewCrashWeb.crashEventName) {
37
+ if (this.dispatchedPendingEvents.has(eventName)) {
38
+ return;
39
+ }
40
+ const value = this.readPendingCrashInfo();
41
+ if (!value || !this.shouldDispatchEvent(eventName, value)) {
42
+ return;
43
+ }
44
+ this.dispatchedPendingEvents.add(eventName);
45
+ this.notifyListeners(eventName, value);
46
+ }
47
+ shouldDispatchEvent(eventName, value) {
48
+ if (eventName === WebViewCrashWeb.crashEventName) {
49
+ return value.reason !== 'periodicRestart' && value.reason !== 'manualRestart';
50
+ }
51
+ return eventName === WebViewCrashWeb.restartEventName;
52
+ }
53
+ buildCrashInfo(reason = 'simulated') {
54
+ var _a;
55
+ const timestamp = Date.now();
56
+ return {
57
+ platform: 'web',
58
+ timestamp,
59
+ timestampISO: new Date(timestamp).toISOString(),
60
+ reason,
61
+ url: (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href,
62
+ appState: 'active',
63
+ };
64
+ }
65
+ readPendingCrashInfo() {
66
+ var _a;
67
+ const raw = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(WebViewCrashWeb.storageKey);
68
+ if (!raw) {
69
+ return null;
70
+ }
71
+ try {
72
+ return JSON.parse(raw);
73
+ }
74
+ catch (_b) {
75
+ return null;
76
+ }
77
+ }
78
+ writePendingCrashInfo(value) {
79
+ var _a;
80
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(WebViewCrashWeb.storageKey, JSON.stringify(value));
81
+ }
82
+ removePendingCrashInfo() {
83
+ var _a;
84
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(WebViewCrashWeb.storageKey);
85
+ }
86
+ }
87
+ WebViewCrashWeb.crashEventName = 'webViewRestoredAfterCrash';
88
+ WebViewCrashWeb.restartEventName = 'webViewRestoredAfterRestart';
89
+ WebViewCrashWeb.storageKey = 'capgo.webview-crash.pending';
90
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAA9C;;QACU,4BAAuB,GAAG,IAAI,GAAG,EAAU,CAAC;IA8FtD,CAAC;IA5FC,KAAK,CAAC,mBAAmB;QACvB,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC;IAChD,CAAC;IAED,KAAK,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AC,KAAuB;;QACnD,MAAA,UAAU,CAAC,YAAY,0CAAE,OAAO,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACtF,CAAC;IAEO,sBAAsB;;QAC5B,MAAA,UAAU,CAAC,YAAY,0CAAE,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IAClE,CAAC;;AAEuB,8BAAc,GAAG,2BAA2B,AAA9B,CAA+B;AAC7C,gCAAgB,GAAG,6BAA6B,AAAhC,CAAiC;AACjD,0BAAU,GAAG,6BAA6B,AAAhC,CAAiC","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\nimport { WebPlugin } from '@capacitor/core';\n\nimport type { PendingCrashInfoResult, WebViewCrashInfo, WebViewCrashPlugin } from './definitions';\n\nexport class WebViewCrashWeb extends WebPlugin implements WebViewCrashPlugin {\n private dispatchedPendingEvents = new Set<string>();\n\n async getPendingCrashInfo(): Promise<PendingCrashInfoResult> {\n return { value: this.readPendingCrashInfo() };\n }\n\n async clearPendingCrashInfo(): Promise<void> {\n this.removePendingCrashInfo();\n this.dispatchedPendingEvents.clear();\n }\n\n async simulateCrashRecovery(): Promise<PendingCrashInfoResult> {\n const value = this.buildCrashInfo();\n this.writePendingCrashInfo(value);\n this.dispatchedPendingEvents.clear();\n this.flushPendingCrashEvent();\n this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);\n return { value };\n }\n\n async restartWebView(): Promise<PendingCrashInfoResult> {\n const value = this.buildCrashInfo('manualRestart');\n this.writePendingCrashInfo(value);\n this.dispatchedPendingEvents.clear();\n this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);\n return { value };\n }\n\n async addListener(eventName: string, listenerFunc: (...args: any[]) => any): Promise<PluginListenerHandle> {\n const handle = await super.addListener(eventName, listenerFunc);\n if (eventName === WebViewCrashWeb.crashEventName || eventName === WebViewCrashWeb.restartEventName) {\n this.flushPendingCrashEvent(eventName);\n }\n return handle;\n }\n\n private flushPendingCrashEvent(eventName = WebViewCrashWeb.crashEventName): void {\n if (this.dispatchedPendingEvents.has(eventName)) {\n return;\n }\n\n const value = this.readPendingCrashInfo();\n if (!value || !this.shouldDispatchEvent(eventName, value)) {\n return;\n }\n\n this.dispatchedPendingEvents.add(eventName);\n this.notifyListeners(eventName, value);\n }\n\n private shouldDispatchEvent(eventName: string, value: WebViewCrashInfo): boolean {\n if (eventName === WebViewCrashWeb.crashEventName) {\n return value.reason !== 'periodicRestart' && value.reason !== 'manualRestart';\n }\n\n return eventName === WebViewCrashWeb.restartEventName;\n }\n\n private buildCrashInfo(reason: WebViewCrashInfo['reason'] = 'simulated'): WebViewCrashInfo {\n const timestamp = Date.now();\n return {\n platform: 'web',\n timestamp,\n timestampISO: new Date(timestamp).toISOString(),\n reason,\n url: globalThis.location?.href,\n appState: 'active',\n };\n }\n\n private readPendingCrashInfo(): WebViewCrashInfo | null {\n const raw = globalThis.localStorage?.getItem(WebViewCrashWeb.storageKey);\n if (!raw) {\n return null;\n }\n\n try {\n return JSON.parse(raw) as WebViewCrashInfo;\n } catch {\n return null;\n }\n }\n\n private writePendingCrashInfo(value: WebViewCrashInfo): void {\n globalThis.localStorage?.setItem(WebViewCrashWeb.storageKey, JSON.stringify(value));\n }\n\n private removePendingCrashInfo(): void {\n globalThis.localStorage?.removeItem(WebViewCrashWeb.storageKey);\n }\n\n private static readonly crashEventName = 'webViewRestoredAfterCrash';\n private static readonly restartEventName = 'webViewRestoredAfterRestart';\n private static readonly storageKey = 'capgo.webview-crash.pending';\n}\n"]}
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const WebViewCrash = core.registerPlugin('WebViewCrash', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.WebViewCrashWeb()),
7
+ });
8
+
9
+ class WebViewCrashWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.dispatchedPendingEvents = new Set();
13
+ }
14
+ async getPendingCrashInfo() {
15
+ return { value: this.readPendingCrashInfo() };
16
+ }
17
+ async clearPendingCrashInfo() {
18
+ this.removePendingCrashInfo();
19
+ this.dispatchedPendingEvents.clear();
20
+ }
21
+ async simulateCrashRecovery() {
22
+ const value = this.buildCrashInfo();
23
+ this.writePendingCrashInfo(value);
24
+ this.dispatchedPendingEvents.clear();
25
+ this.flushPendingCrashEvent();
26
+ this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);
27
+ return { value };
28
+ }
29
+ async restartWebView() {
30
+ const value = this.buildCrashInfo('manualRestart');
31
+ this.writePendingCrashInfo(value);
32
+ this.dispatchedPendingEvents.clear();
33
+ this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);
34
+ return { value };
35
+ }
36
+ async addListener(eventName, listenerFunc) {
37
+ const handle = await super.addListener(eventName, listenerFunc);
38
+ if (eventName === WebViewCrashWeb.crashEventName || eventName === WebViewCrashWeb.restartEventName) {
39
+ this.flushPendingCrashEvent(eventName);
40
+ }
41
+ return handle;
42
+ }
43
+ flushPendingCrashEvent(eventName = WebViewCrashWeb.crashEventName) {
44
+ if (this.dispatchedPendingEvents.has(eventName)) {
45
+ return;
46
+ }
47
+ const value = this.readPendingCrashInfo();
48
+ if (!value || !this.shouldDispatchEvent(eventName, value)) {
49
+ return;
50
+ }
51
+ this.dispatchedPendingEvents.add(eventName);
52
+ this.notifyListeners(eventName, value);
53
+ }
54
+ shouldDispatchEvent(eventName, value) {
55
+ if (eventName === WebViewCrashWeb.crashEventName) {
56
+ return value.reason !== 'periodicRestart' && value.reason !== 'manualRestart';
57
+ }
58
+ return eventName === WebViewCrashWeb.restartEventName;
59
+ }
60
+ buildCrashInfo(reason = 'simulated') {
61
+ var _a;
62
+ const timestamp = Date.now();
63
+ return {
64
+ platform: 'web',
65
+ timestamp,
66
+ timestampISO: new Date(timestamp).toISOString(),
67
+ reason,
68
+ url: (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href,
69
+ appState: 'active',
70
+ };
71
+ }
72
+ readPendingCrashInfo() {
73
+ var _a;
74
+ const raw = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(WebViewCrashWeb.storageKey);
75
+ if (!raw) {
76
+ return null;
77
+ }
78
+ try {
79
+ return JSON.parse(raw);
80
+ }
81
+ catch (_b) {
82
+ return null;
83
+ }
84
+ }
85
+ writePendingCrashInfo(value) {
86
+ var _a;
87
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(WebViewCrashWeb.storageKey, JSON.stringify(value));
88
+ }
89
+ removePendingCrashInfo() {
90
+ var _a;
91
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(WebViewCrashWeb.storageKey);
92
+ }
93
+ }
94
+ WebViewCrashWeb.crashEventName = 'webViewRestoredAfterCrash';
95
+ WebViewCrashWeb.restartEventName = 'webViewRestoredAfterRestart';
96
+ WebViewCrashWeb.storageKey = 'capgo.webview-crash.pending';
97
+
98
+ var web = /*#__PURE__*/Object.freeze({
99
+ __proto__: null,
100
+ WebViewCrashWeb: WebViewCrashWeb
101
+ });
102
+
103
+ exports.WebViewCrash = WebViewCrash;
104
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst WebViewCrash = registerPlugin('WebViewCrash', {\n web: () => import('./web').then((m) => new m.WebViewCrashWeb()),\n});\nexport * from './definitions';\nexport { WebViewCrash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class WebViewCrashWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.dispatchedPendingEvents = new Set();\n }\n async getPendingCrashInfo() {\n return { value: this.readPendingCrashInfo() };\n }\n async clearPendingCrashInfo() {\n this.removePendingCrashInfo();\n this.dispatchedPendingEvents.clear();\n }\n async simulateCrashRecovery() {\n const value = this.buildCrashInfo();\n this.writePendingCrashInfo(value);\n this.dispatchedPendingEvents.clear();\n this.flushPendingCrashEvent();\n this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);\n return { value };\n }\n async restartWebView() {\n const value = this.buildCrashInfo('manualRestart');\n this.writePendingCrashInfo(value);\n this.dispatchedPendingEvents.clear();\n this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);\n return { value };\n }\n async addListener(eventName, listenerFunc) {\n const handle = await super.addListener(eventName, listenerFunc);\n if (eventName === WebViewCrashWeb.crashEventName || eventName === WebViewCrashWeb.restartEventName) {\n this.flushPendingCrashEvent(eventName);\n }\n return handle;\n }\n flushPendingCrashEvent(eventName = WebViewCrashWeb.crashEventName) {\n if (this.dispatchedPendingEvents.has(eventName)) {\n return;\n }\n const value = this.readPendingCrashInfo();\n if (!value || !this.shouldDispatchEvent(eventName, value)) {\n return;\n }\n this.dispatchedPendingEvents.add(eventName);\n this.notifyListeners(eventName, value);\n }\n shouldDispatchEvent(eventName, value) {\n if (eventName === WebViewCrashWeb.crashEventName) {\n return value.reason !== 'periodicRestart' && value.reason !== 'manualRestart';\n }\n return eventName === WebViewCrashWeb.restartEventName;\n }\n buildCrashInfo(reason = 'simulated') {\n var _a;\n const timestamp = Date.now();\n return {\n platform: 'web',\n timestamp,\n timestampISO: new Date(timestamp).toISOString(),\n reason,\n url: (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href,\n appState: 'active',\n };\n }\n readPendingCrashInfo() {\n var _a;\n const raw = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(WebViewCrashWeb.storageKey);\n if (!raw) {\n return null;\n }\n try {\n return JSON.parse(raw);\n }\n catch (_b) {\n return null;\n }\n }\n writePendingCrashInfo(value) {\n var _a;\n (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(WebViewCrashWeb.storageKey, JSON.stringify(value));\n }\n removePendingCrashInfo() {\n var _a;\n (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(WebViewCrashWeb.storageKey);\n }\n}\nWebViewCrashWeb.crashEventName = 'webViewRestoredAfterCrash';\nWebViewCrashWeb.restartEventName = 'webViewRestoredAfterRestart';\nWebViewCrashWeb.storageKey = 'capgo.webview-crash.pending';\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE;AAChD,IAAI;AACJ,IAAI,MAAM,mBAAmB,GAAG;AAChC,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,oBAAoB,EAAE,EAAE;AACrD,IAAI;AACJ,IAAI,MAAM,qBAAqB,GAAG;AAClC,QAAQ,IAAI,CAAC,sBAAsB,EAAE;AACrC,QAAQ,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE;AAC5C,IAAI;AACJ,IAAI,MAAM,qBAAqB,GAAG;AAClC,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE;AAC3C,QAAQ,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC;AACzC,QAAQ,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE;AAC5C,QAAQ,IAAI,CAAC,sBAAsB,EAAE;AACrC,QAAQ,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,gBAAgB,CAAC;AACrE,QAAQ,OAAO,EAAE,KAAK,EAAE;AACxB,IAAI;AACJ,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,MAAM,KAAK,GAAG,IAAI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,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACzI,IAAI;AACJ,IAAI,sBAAsB,GAAG;AAC7B,QAAQ,IAAI,EAAE;AACd,QAAQ,CAAC,EAAE,GAAG,UAAU,CAAC,YAAY,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC;AACrH,IAAI;AACJ;AACA,eAAe,CAAC,cAAc,GAAG,2BAA2B;AAC5D,eAAe,CAAC,gBAAgB,GAAG,6BAA6B;AAChE,eAAe,CAAC,UAAU,GAAG,6BAA6B;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,107 @@
1
+ var capacitorWebViewCrash = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const WebViewCrash = core.registerPlugin('WebViewCrash', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.WebViewCrashWeb()),
6
+ });
7
+
8
+ class WebViewCrashWeb extends core.WebPlugin {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.dispatchedPendingEvents = new Set();
12
+ }
13
+ async getPendingCrashInfo() {
14
+ return { value: this.readPendingCrashInfo() };
15
+ }
16
+ async clearPendingCrashInfo() {
17
+ this.removePendingCrashInfo();
18
+ this.dispatchedPendingEvents.clear();
19
+ }
20
+ async simulateCrashRecovery() {
21
+ const value = this.buildCrashInfo();
22
+ this.writePendingCrashInfo(value);
23
+ this.dispatchedPendingEvents.clear();
24
+ this.flushPendingCrashEvent();
25
+ this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);
26
+ return { value };
27
+ }
28
+ async restartWebView() {
29
+ const value = this.buildCrashInfo('manualRestart');
30
+ this.writePendingCrashInfo(value);
31
+ this.dispatchedPendingEvents.clear();
32
+ this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);
33
+ return { value };
34
+ }
35
+ async addListener(eventName, listenerFunc) {
36
+ const handle = await super.addListener(eventName, listenerFunc);
37
+ if (eventName === WebViewCrashWeb.crashEventName || eventName === WebViewCrashWeb.restartEventName) {
38
+ this.flushPendingCrashEvent(eventName);
39
+ }
40
+ return handle;
41
+ }
42
+ flushPendingCrashEvent(eventName = WebViewCrashWeb.crashEventName) {
43
+ if (this.dispatchedPendingEvents.has(eventName)) {
44
+ return;
45
+ }
46
+ const value = this.readPendingCrashInfo();
47
+ if (!value || !this.shouldDispatchEvent(eventName, value)) {
48
+ return;
49
+ }
50
+ this.dispatchedPendingEvents.add(eventName);
51
+ this.notifyListeners(eventName, value);
52
+ }
53
+ shouldDispatchEvent(eventName, value) {
54
+ if (eventName === WebViewCrashWeb.crashEventName) {
55
+ return value.reason !== 'periodicRestart' && value.reason !== 'manualRestart';
56
+ }
57
+ return eventName === WebViewCrashWeb.restartEventName;
58
+ }
59
+ buildCrashInfo(reason = 'simulated') {
60
+ var _a;
61
+ const timestamp = Date.now();
62
+ return {
63
+ platform: 'web',
64
+ timestamp,
65
+ timestampISO: new Date(timestamp).toISOString(),
66
+ reason,
67
+ url: (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href,
68
+ appState: 'active',
69
+ };
70
+ }
71
+ readPendingCrashInfo() {
72
+ var _a;
73
+ const raw = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(WebViewCrashWeb.storageKey);
74
+ if (!raw) {
75
+ return null;
76
+ }
77
+ try {
78
+ return JSON.parse(raw);
79
+ }
80
+ catch (_b) {
81
+ return null;
82
+ }
83
+ }
84
+ writePendingCrashInfo(value) {
85
+ var _a;
86
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(WebViewCrashWeb.storageKey, JSON.stringify(value));
87
+ }
88
+ removePendingCrashInfo() {
89
+ var _a;
90
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(WebViewCrashWeb.storageKey);
91
+ }
92
+ }
93
+ WebViewCrashWeb.crashEventName = 'webViewRestoredAfterCrash';
94
+ WebViewCrashWeb.restartEventName = 'webViewRestoredAfterRestart';
95
+ WebViewCrashWeb.storageKey = 'capgo.webview-crash.pending';
96
+
97
+ var web = /*#__PURE__*/Object.freeze({
98
+ __proto__: null,
99
+ WebViewCrashWeb: WebViewCrashWeb
100
+ });
101
+
102
+ exports.WebViewCrash = WebViewCrash;
103
+
104
+ return exports;
105
+
106
+ })({}, capacitorExports);
107
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst WebViewCrash = registerPlugin('WebViewCrash', {\n web: () => import('./web').then((m) => new m.WebViewCrashWeb()),\n});\nexport * from './definitions';\nexport { WebViewCrash };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class WebViewCrashWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.dispatchedPendingEvents = new Set();\n }\n async getPendingCrashInfo() {\n return { value: this.readPendingCrashInfo() };\n }\n async clearPendingCrashInfo() {\n this.removePendingCrashInfo();\n this.dispatchedPendingEvents.clear();\n }\n async simulateCrashRecovery() {\n const value = this.buildCrashInfo();\n this.writePendingCrashInfo(value);\n this.dispatchedPendingEvents.clear();\n this.flushPendingCrashEvent();\n this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);\n return { value };\n }\n async restartWebView() {\n const value = this.buildCrashInfo('manualRestart');\n this.writePendingCrashInfo(value);\n this.dispatchedPendingEvents.clear();\n this.flushPendingCrashEvent(WebViewCrashWeb.restartEventName);\n return { value };\n }\n async addListener(eventName, listenerFunc) {\n const handle = await super.addListener(eventName, listenerFunc);\n if (eventName === WebViewCrashWeb.crashEventName || eventName === WebViewCrashWeb.restartEventName) {\n this.flushPendingCrashEvent(eventName);\n }\n return handle;\n }\n flushPendingCrashEvent(eventName = WebViewCrashWeb.crashEventName) {\n if (this.dispatchedPendingEvents.has(eventName)) {\n return;\n }\n const value = this.readPendingCrashInfo();\n if (!value || !this.shouldDispatchEvent(eventName, value)) {\n return;\n }\n this.dispatchedPendingEvents.add(eventName);\n this.notifyListeners(eventName, value);\n }\n shouldDispatchEvent(eventName, value) {\n if (eventName === WebViewCrashWeb.crashEventName) {\n return value.reason !== 'periodicRestart' && value.reason !== 'manualRestart';\n }\n return eventName === WebViewCrashWeb.restartEventName;\n }\n buildCrashInfo(reason = 'simulated') {\n var _a;\n const timestamp = Date.now();\n return {\n platform: 'web',\n timestamp,\n timestampISO: new Date(timestamp).toISOString(),\n reason,\n url: (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href,\n appState: 'active',\n };\n }\n readPendingCrashInfo() {\n var _a;\n const raw = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(WebViewCrashWeb.storageKey);\n if (!raw) {\n return null;\n }\n try {\n return JSON.parse(raw);\n }\n catch (_b) {\n return null;\n }\n }\n writePendingCrashInfo(value) {\n var _a;\n (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(WebViewCrashWeb.storageKey, JSON.stringify(value));\n }\n removePendingCrashInfo() {\n var _a;\n (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(WebViewCrashWeb.storageKey);\n }\n}\nWebViewCrashWeb.crashEventName = 'webViewRestoredAfterCrash';\nWebViewCrashWeb.restartEventName = 'webViewRestoredAfterRestart';\nWebViewCrashWeb.storageKey = 'capgo.webview-crash.pending';\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG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