|
1 | 1 | // delete all chrome specific apis, or apis that are not supported by any browser other than chrome |
2 | 2 | // these are not worth emulating and typically cause issues |
3 | 3 |
|
4 | | -import { isemulatedsw } from "@client/entry"; |
| 4 | +import { isemulatedsw, iswindow } from "@client/entry"; |
5 | 5 | import { ScramjetClient } from "@client/index"; |
6 | 6 |
|
7 | 7 | // type self as any here, most of these are not defined in the types |
8 | 8 | export default function (client: ScramjetClient, self: any) { |
| 9 | + const del = (name: string) => { |
| 10 | + const split = name.split("."); |
| 11 | + const prop = split.pop(); |
| 12 | + const target = split.reduce((a, b) => a?.[b], self); |
| 13 | + if (!target) return; |
| 14 | + if (prop && prop in target) { |
| 15 | + delete target[prop]; |
| 16 | + } else { |
| 17 | + } |
| 18 | + }; |
| 19 | + |
9 | 20 | // obviously |
10 | | - delete self.chrome; |
| 21 | + del("chrome"); |
11 | 22 |
|
12 | 23 | // ShapeDetector https://developer.chrome.com/docs/capabilities/shape-detection |
13 | | - delete self.BarcodeDetector; |
14 | | - delete self.FaceDetector; |
15 | | - delete self.TextDetector; |
| 24 | + del("BarcodeDetector"); |
| 25 | + del("FaceDetector"); |
| 26 | + del("TextDetector"); |
16 | 27 |
|
17 | 28 | // background synchronization api |
18 | | - if (window) { |
19 | | - delete self.ServiceWorkerRegistration.prototype.sync; |
| 29 | + if (iswindow) { |
| 30 | + del("ServiceWorkerRegistration.prototype.sync"); |
20 | 31 | } |
21 | 32 | if (isemulatedsw) { |
22 | | - delete self.SyncManager; |
23 | | - delete self.SyncEvent; |
| 33 | + del("SyncManager"); |
| 34 | + del("SyncEvent"); |
24 | 35 | } |
25 | 36 |
|
26 | 37 | // trustedtypes |
27 | | - delete self.TrustedHTML; |
28 | | - delete self.TrustedScript; |
29 | | - delete self.TrustedScriptURL; |
30 | | - delete self.TrustedTypePolicy; |
31 | | - delete self.TrustedTypePolicyFactory; |
| 38 | + del("TrustedHTML"); |
| 39 | + del("TrustedScript"); |
| 40 | + del("TrustedScriptURL"); |
| 41 | + del("TrustedTypePolicy"); |
| 42 | + del("TrustedTypePolicyFactory"); |
32 | 43 | self.__defineGetter__("trustedTypes", () => undefined); |
33 | 44 |
|
34 | 45 | // whatever this is |
35 | | - delete self.Navigator.prototype.joinAdInterestGroup; |
| 46 | + del("Navigator.prototype.joinAdInterestGroup"); |
36 | 47 |
|
37 | | - if (!window) return; |
| 48 | + if (!iswindow) return; |
38 | 49 | // DOM specific ones below here |
39 | 50 |
|
40 | | - delete self.MediaDevices.prototype.setCaptureHandleConfig; |
| 51 | + del("MediaDevices.prototype.setCaptureHandleConfig"); |
41 | 52 |
|
42 | 53 | // web bluetooth api |
43 | | - delete self.Navigator.prototype.bluetooth; |
44 | | - delete self.Bluetooth; |
45 | | - delete self.BluetoothDevice; |
46 | | - delete self.BluetoothRemoteGATTServer; |
47 | | - delete self.BluetoothRemoteGATTCharacteristic; |
48 | | - delete self.BluetoothRemoteGATTDescriptor; |
49 | | - delete self.BluetoothUUID; |
| 54 | + del("Navigator.prototype.bluetooth"); |
| 55 | + del("Bluetooth"); |
| 56 | + del("BluetoothDevice"); |
| 57 | + del("BluetoothRemoteGATTServer"); |
| 58 | + del("BluetoothRemoteGATTCharacteristic"); |
| 59 | + del("BluetoothRemoteGATTDescriptor"); |
| 60 | + del("BluetoothUUID"); |
50 | 61 |
|
51 | 62 | // contact picker api |
52 | | - delete self.Navigator.prototype.contacts; |
53 | | - delete self.ContactAddress; |
54 | | - delete self.ContactManager; |
| 63 | + del("Navigator.prototype.contacts"); |
| 64 | + del("ContactAddress"); |
| 65 | + del("ContactManager"); |
55 | 66 |
|
56 | 67 | // Idle Detection API |
57 | | - delete self.IdleDetector; |
| 68 | + del("IdleDetector"); |
58 | 69 |
|
59 | 70 | // Presentation API |
60 | | - delete self.Navigator.prototype.presentation; |
61 | | - delete self.Presentation; |
62 | | - delete self.PresentationConnection; |
63 | | - delete self.PresentationReceiver; |
64 | | - delete self.PresentationRequest; |
65 | | - delete self.PresentationAvailability; |
66 | | - delete self.PresentationConnectionAvailableEvent; |
67 | | - delete self.PresentationConnectionCloseEvent; |
68 | | - delete self.PresentationConnectionList; |
| 71 | + del("Navigator.prototype.presentation"); |
| 72 | + del("Presentation"); |
| 73 | + del("PresentationConnection"); |
| 74 | + del("PresentationReceiver"); |
| 75 | + del("PresentationRequest"); |
| 76 | + del("PresentationAvailability"); |
| 77 | + del("PresentationConnectionAvailableEvent"); |
| 78 | + del("PresentationConnectionCloseEvent"); |
| 79 | + del("PresentationConnectionList"); |
69 | 80 |
|
70 | 81 | // Window Controls Overlay API |
71 | | - delete self.WindowControlsOverlay; |
72 | | - delete self.WindowControlsOverlayGeometryChangeEvent; |
73 | | - delete self.Navigator.prototype.windowControlsOverlay; |
| 82 | + del("WindowControlsOverlay"); |
| 83 | + del("WindowControlsOverlayGeometryChangeEvent"); |
| 84 | + del("Navigator.prototype.windowControlsOverlay"); |
74 | 85 |
|
75 | 86 | // WebHID API |
76 | | - delete self.Navigator.prototype.hid; |
77 | | - delete self.HID; |
78 | | - delete self.HIDDevice; |
79 | | - delete self.HIDConnectionEvent; |
80 | | - delete self.HIDInputReportEvent; |
| 87 | + del("Navigator.prototype.hid"); |
| 88 | + del("HID"); |
| 89 | + del("HIDDevice"); |
| 90 | + del("HIDConnectionEvent"); |
| 91 | + del("HIDInputReportEvent"); |
81 | 92 |
|
82 | 93 | // Navigation API (not chrome only but it's really annoying to implement) |
83 | | - delete self.navigation; |
84 | | - delete self.NavigateEvent; |
85 | | - delete self.NavigationActivation; |
86 | | - delete self.NavigationCurrentEntryChangeEvent; |
87 | | - delete self.NavigationDestination; |
88 | | - delete self.NavigationHistoryEntry; |
89 | | - delete self.NavigationTransition; |
| 94 | + del("navigation"); |
| 95 | + del("NavigateEvent"); |
| 96 | + del("NavigationActivation"); |
| 97 | + del("NavigationCurrentEntryChangeEvent"); |
| 98 | + del("NavigationDestination"); |
| 99 | + del("NavigationHistoryEntry"); |
| 100 | + del("NavigationTransition"); |
90 | 101 | } |
0 commit comments