|
1 | | -/*! © DuckDuckGo ContentScopeScripts protections https://github.com/duckduckgo/content-scope-scripts/ */ |
| 1 | +/*! © DuckDuckGo ContentScopeScripts android https://github.com/duckduckgo/content-scope-scripts/ */ |
2 | 2 | "use strict"; |
3 | 3 | (() => { |
4 | 4 | var __create = Object.create; |
|
824 | 824 | TypeError: () => TypeError2, |
825 | 825 | URL: () => URL2, |
826 | 826 | addEventListener: () => addEventListener, |
| 827 | + console: () => console2, |
| 828 | + consoleError: () => consoleError, |
| 829 | + consoleLog: () => consoleLog, |
| 830 | + consoleWarn: () => consoleWarn, |
827 | 831 | customElementsDefine: () => customElementsDefine, |
828 | 832 | customElementsGet: () => customElementsGet, |
829 | 833 | dispatchEvent: () => dispatchEvent, |
|
864 | 868 | var Map2 = globalThis.Map; |
865 | 869 | var Error2 = globalThis.Error; |
866 | 870 | var randomUUID = globalThis.crypto?.randomUUID?.bind(globalThis.crypto); |
| 871 | + var console2 = globalThis.console; |
| 872 | + var consoleLog = console2.log.bind(console2); |
| 873 | + var consoleWarn = console2.warn.bind(console2); |
| 874 | + var consoleError = console2.error.bind(console2); |
867 | 875 |
|
868 | 876 | // src/utils.js |
869 | 877 | var globalObj = typeof window === "undefined" ? globalThis : window; |
|
4939 | 4947 | return () => { |
4940 | 4948 | }; |
4941 | 4949 | } |
4942 | | - return console.log.bind(console, prefix); |
| 4950 | + return consoleLog.bind(console, prefix); |
4943 | 4951 | }, |
4944 | 4952 | get warn() { |
4945 | 4953 | if (!shouldLog) { |
4946 | 4954 | return () => { |
4947 | 4955 | }; |
4948 | 4956 | } |
4949 | | - return console.warn.bind(console, prefix); |
| 4957 | + return consoleWarn.bind(console, prefix); |
4950 | 4958 | }, |
4951 | 4959 | get error() { |
4952 | 4960 | if (!shouldLog) { |
4953 | 4961 | return () => { |
4954 | 4962 | }; |
4955 | 4963 | } |
4956 | | - return console.error.bind(console, prefix); |
| 4964 | + return consoleError.bind(console, prefix); |
4957 | 4965 | } |
4958 | 4966 | }; |
4959 | 4967 | } |
|
6089 | 6097 | // src/features/message-bridge/create-page-world-bridge.js |
6090 | 6098 | var captured = captured_globals_exports; |
6091 | 6099 | var ERROR_MSG = "Did not install Message Bridge"; |
6092 | | - function createPageWorldBridge(featureName, token) { |
| 6100 | + function createPageWorldBridge(featureName, token, context) { |
6093 | 6101 | if (typeof featureName !== "string" || !token) { |
6094 | 6102 | throw new captured.Error(ERROR_MSG); |
6095 | 6103 | } |
|
6120 | 6128 | if (!installed) { |
6121 | 6129 | throw new captured.Error(ERROR_MSG); |
6122 | 6130 | } |
6123 | | - return createMessagingInterface(featureName, send, appendToken); |
| 6131 | + return createMessagingInterface(featureName, send, appendToken, context); |
6124 | 6132 | } |
6125 | 6133 | function random() { |
6126 | 6134 | if (typeof captured.randomUUID !== "function") throw new Error("unreachable"); |
6127 | 6135 | return captured.randomUUID(); |
6128 | 6136 | } |
6129 | | - function createMessagingInterface(featureName, send, appendToken) { |
| 6137 | + function createMessagingInterface(featureName, send, appendToken, context) { |
6130 | 6138 | return { |
6131 | 6139 | /** |
6132 | 6140 | * @param {string} method |
6133 | 6141 | * @param {Record<string, any>} params |
6134 | 6142 | */ |
6135 | 6143 | notify(method, params) { |
| 6144 | + context?.log.info("sending notify", method, params); |
6136 | 6145 | send( |
6137 | 6146 | new ProxyNotification({ |
6138 | 6147 | method, |
|
6147 | 6156 | * @returns {Promise<any>} |
6148 | 6157 | */ |
6149 | 6158 | request(method, params) { |
| 6159 | + context?.log.info("sending request", method, params); |
6150 | 6160 | const id = random(); |
6151 | 6161 | send( |
6152 | 6162 | new ProxyRequest({ |
|
6159 | 6169 | return new Promise((resolve, reject) => { |
6160 | 6170 | const responseName = appendToken(ProxyResponse.NAME + "-" + id); |
6161 | 6171 | const handler = (e) => { |
| 6172 | + context?.log.info("received response", e.detail); |
6162 | 6173 | const response = ProxyResponse.create(e.detail); |
6163 | 6174 | if (response && response.id === id) { |
6164 | 6175 | if ("error" in response && response.error) { |
|
6179 | 6190 | */ |
6180 | 6191 | subscribe(name, callback) { |
6181 | 6192 | const id = random(); |
| 6193 | + context?.log.info("subscribing", name); |
6182 | 6194 | send( |
6183 | 6195 | new SubscriptionRequest({ |
6184 | 6196 | subscriptionName: name, |
|
6187 | 6199 | }) |
6188 | 6200 | ); |
6189 | 6201 | const handler = (e) => { |
| 6202 | + context?.log.info("received subscription response", e.detail); |
6190 | 6203 | const subscriptionEvent = SubscriptionResponse.create(e.detail); |
6191 | 6204 | if (subscriptionEvent) { |
6192 | 6205 | const { id: eventId, params } = subscriptionEvent; |
|
6225 | 6238 | if (!args.platform || !args.platform.name) { |
6226 | 6239 | return; |
6227 | 6240 | } |
| 6241 | + const context = this; |
6228 | 6242 | this.defineProperty(Navigator.prototype, "duckduckgo", { |
6229 | 6243 | value: { |
6230 | 6244 | platform: args.platform.name, |
|
6240 | 6254 | createMessageBridge(featureName) { |
6241 | 6255 | const existingBridge = store[featureName]; |
6242 | 6256 | if (existingBridge) return existingBridge; |
6243 | | - const bridge = createPageWorldBridge(featureName, args.messageSecret); |
| 6257 | + const bridge = createPageWorldBridge(featureName, args.messageSecret, context); |
6244 | 6258 | store[featureName] = bridge; |
6245 | 6259 | return bridge; |
6246 | 6260 | } |
|
0 commit comments