@trezor/connect-web
Advanced tools
Comparing version 9.4.8-beta.2 to 9.5.0-beta.1
@@ -6,2 +6,6 @@ "use strict"; | ||
class ServiceWorkerWindowChannel extends connect_common_1.AbstractMessageChannel { | ||
port; | ||
name; | ||
allowSelfOrigin; | ||
currentId; | ||
constructor({ name, channel, logger, lazyHandshake, legacyMode, allowSelfOrigin = false, currentId, }) { | ||
@@ -26,12 +30,10 @@ super({ | ||
chrome.runtime.onConnect.addListener(port => { | ||
var _a, _b, _c, _d; | ||
if (port.name !== this.name) | ||
return; | ||
if (((_a = this.currentId) === null || _a === void 0 ? void 0 : _a.call(this)) && ((_b = this.currentId) === null || _b === void 0 ? void 0 : _b.call(this)) !== ((_d = (_c = port.sender) === null || _c === void 0 ? void 0 : _c.tab) === null || _d === void 0 ? void 0 : _d.id)) | ||
if (this.currentId?.() && this.currentId?.() !== port.sender?.tab?.id) | ||
return; | ||
this.port = port; | ||
this.port.onMessage.addListener((message, { sender }) => { | ||
var _a, _b, _c, _d, _e; | ||
if (!sender) { | ||
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error('service-worker-window', 'no sender'); | ||
this.logger?.error('service-worker-window', 'no sender'); | ||
return; | ||
@@ -47,7 +49,7 @@ } | ||
]; | ||
const webextensionId = (_b = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _b === void 0 ? void 0 : _b.id; | ||
const webextensionId = chrome?.runtime?.id; | ||
if (webextensionId) { | ||
whitelist.push(`chrome-extension://${webextensionId}`); | ||
} | ||
const webextensionUrl = (_c = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _c === void 0 ? void 0 : _c.getURL(''); | ||
const webextensionUrl = chrome?.runtime?.getURL(''); | ||
if (webextensionUrl) { | ||
@@ -57,7 +59,7 @@ whitelist.push(webextensionUrl.slice(0, -1)); | ||
if (!origin) { | ||
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.error('connect-webextension/messageChannel/extensionPort/onMessage', 'no origin'); | ||
this.logger?.error('connect-webextension/messageChannel/extensionPort/onMessage', 'no origin'); | ||
return; | ||
} | ||
if (!whitelist.includes(origin)) { | ||
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.error('connect-webextension/messageChannel/extensionPort/onMessage', 'origin not whitelisted', origin); | ||
this.logger?.error('connect-webextension/messageChannel/extensionPort/onMessage', 'origin not whitelisted', origin); | ||
return; | ||
@@ -74,6 +76,5 @@ } | ||
disconnect() { | ||
var _a; | ||
if (!this.isConnected) | ||
return; | ||
(_a = this.port) === null || _a === void 0 ? void 0 : _a.disconnect(); | ||
this.port?.disconnect(); | ||
this.clear(); | ||
@@ -80,0 +81,0 @@ this.isConnected = false; |
@@ -6,2 +6,3 @@ "use strict"; | ||
class WindowServiceWorkerChannel extends connect_common_1.AbstractMessageChannel { | ||
port; | ||
constructor({ name, channel, }) { | ||
@@ -21,4 +22,3 @@ super({ | ||
connect() { | ||
var _a; | ||
(_a = this.port) === null || _a === void 0 ? void 0 : _a.onMessage.addListener((message) => { | ||
this.port?.onMessage.addListener((message) => { | ||
if (message.channel.here === this.channel.here) | ||
@@ -31,6 +31,5 @@ return; | ||
disconnect() { | ||
var _a; | ||
if (!this.isConnected) | ||
return; | ||
(_a = this.port) === null || _a === void 0 ? void 0 : _a.disconnect(); | ||
this.port?.disconnect(); | ||
this.isConnected = false; | ||
@@ -37,0 +36,0 @@ } |
@@ -6,2 +6,4 @@ "use strict"; | ||
class WindowWindowChannel extends connect_common_1.AbstractMessageChannel { | ||
_windowHere; | ||
_listener; | ||
constructor({ windowHere, windowPeer, channel, logger, origin, legacyMode, }) { | ||
@@ -11,4 +13,3 @@ super({ | ||
sendFn: (message) => { | ||
var _a; | ||
(_a = windowPeer()) === null || _a === void 0 ? void 0 : _a.postMessage(message, origin); | ||
windowPeer()?.postMessage(message, origin); | ||
}, | ||
@@ -23,6 +24,12 @@ logger, | ||
listener(event) { | ||
const message = Object.assign(Object.assign({}, event.data), { success: true, origin: event.origin, payload: event.data.payload || {}, channel: event.data.channel || { | ||
const message = { | ||
...event.data, | ||
success: true, | ||
origin: event.origin, | ||
payload: event.data.payload || {}, | ||
channel: event.data.channel || { | ||
peer: this.channel.here, | ||
here: this.channel.peer, | ||
} }); | ||
}, | ||
}; | ||
this.onMessage(message); | ||
@@ -29,0 +36,0 @@ } |
@@ -6,4 +6,3 @@ "use strict"; | ||
const getEnv = () => { | ||
var _a; | ||
if (typeof chrome !== 'undefined' && typeof ((_a = chrome.runtime) === null || _a === void 0 ? void 0 : _a.onConnect) !== 'undefined') { | ||
if (typeof chrome !== 'undefined' && typeof chrome.runtime?.onConnect !== 'undefined') { | ||
return 'webextension'; | ||
@@ -36,4 +35,3 @@ } | ||
const parseConnectSettings = (input = {}) => { | ||
var _a; | ||
const settings = Object.assign({ popup: true }, input); | ||
const settings = { popup: true, ...input }; | ||
let globalSrc; | ||
@@ -50,3 +48,3 @@ if (typeof window !== 'undefined') { | ||
} | ||
if (typeof window !== 'undefined' && typeof ((_a = window.location) === null || _a === void 0 ? void 0 : _a.search) === 'string') { | ||
if (typeof window !== 'undefined' && typeof window.location?.search === 'string') { | ||
const query = processQueryString(window.location.search, ['trezor-connect-src']); | ||
@@ -53,0 +51,0 @@ if (query['trezor-connect-src']) { |
@@ -18,3 +18,3 @@ "use strict"; | ||
} | ||
catch (_a) { | ||
catch { | ||
} | ||
@@ -86,3 +86,2 @@ } | ||
const onLoad = () => { | ||
var _a, _b; | ||
if (!exports.instance) { | ||
@@ -93,3 +92,3 @@ exports.initPromise.reject(ERRORS.TypedError('Init_IframeBlocked')); | ||
try { | ||
const iframeOrigin = (_a = exports.instance.contentWindow) === null || _a === void 0 ? void 0 : _a.location.origin; | ||
const iframeOrigin = exports.instance.contentWindow?.location.origin; | ||
if (!iframeOrigin || iframeOrigin === 'null') { | ||
@@ -100,3 +99,3 @@ handleIframeBlocked(); | ||
} | ||
catch (_c) { | ||
catch { | ||
} | ||
@@ -110,3 +109,3 @@ let extension; | ||
} | ||
(_b = exports.instance.contentWindow) === null || _b === void 0 ? void 0 : _b.postMessage({ | ||
exports.instance.contentWindow?.postMessage({ | ||
type: events_1.IFRAME.INIT, | ||
@@ -149,7 +148,6 @@ payload: { | ||
const postMessage = (message) => { | ||
var _a; | ||
if (!exports.instance) { | ||
throw ERRORS.TypedError('Init_IframeBlocked'); | ||
} | ||
(_a = exports.instance.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, exports.origin); | ||
exports.instance.contentWindow?.postMessage(message, exports.origin); | ||
}; | ||
@@ -156,0 +154,0 @@ exports.postMessage = postMessage; |
@@ -17,6 +17,10 @@ "use strict"; | ||
class CoreInIframe { | ||
eventEmitter = new events_1.default(); | ||
_settings; | ||
_log; | ||
_popupManager; | ||
_messagePromises; | ||
boundHandleMessage = this.handleMessage.bind(this); | ||
boundDispose = this.dispose.bind(this); | ||
constructor() { | ||
this.eventEmitter = new events_1.default(); | ||
this.boundHandleMessage = this.handleMessage.bind(this); | ||
this.boundDispose = this.dispose.bind(this); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(); | ||
@@ -37,3 +41,6 @@ this._log = (0, debug_1.initLog)('@trezor/connect-web'); | ||
manifest(data) { | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(Object.assign(Object.assign({}, this._settings), { manifest: data })); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)({ | ||
...this._settings, | ||
manifest: data, | ||
}); | ||
} | ||
@@ -105,11 +112,10 @@ dispose() { | ||
async init(settings) { | ||
var _a, _b; | ||
if (iframe.instance) { | ||
throw ERRORS.TypedError('Init_AlreadyInitialized'); | ||
} | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(Object.assign(Object.assign({}, this._settings), settings)); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)({ ...this._settings, ...settings }); | ||
if (!this._settings.manifest) { | ||
throw ERRORS.TypedError('Init_ManifestMissing'); | ||
} | ||
if (!((_a = this._settings.transports) === null || _a === void 0 ? void 0 : _a.length)) { | ||
if (!this._settings.transports?.length) { | ||
this._settings.transports = ['BridgeTransport', 'WebUsbTransport']; | ||
@@ -136,3 +142,3 @@ } | ||
navigator.usb && | ||
((_b = this._settings.transports) === null || _b === void 0 ? void 0 : _b.includes('WebUsbTransport'))) { | ||
this._settings.transports?.includes('WebUsbTransport')) { | ||
throw ERRORS.TypedError('Transport_Missing'); | ||
@@ -232,7 +238,12 @@ } | ||
window.addEventListener('message', loginChallengeListener, false); | ||
const response = await this.call(Object.assign(Object.assign({ method: 'requestLogin' }, params), { asyncChallenge: true, callback: null })); | ||
const response = await this.call({ | ||
method: 'requestLogin', | ||
...params, | ||
asyncChallenge: true, | ||
callback: null, | ||
}); | ||
window.removeEventListener('message', loginChallengeListener); | ||
return response; | ||
} | ||
return this.call(Object.assign({ method: 'requestLogin' }, params)); | ||
return this.call({ method: 'requestLogin', ...params }); | ||
} | ||
@@ -250,3 +261,3 @@ disableWebUSB() { | ||
} | ||
catch (_a) { | ||
catch { | ||
} | ||
@@ -253,0 +264,0 @@ } |
@@ -14,4 +14,8 @@ "use strict"; | ||
class CoreInPopup { | ||
eventEmitter = new events_1.default(); | ||
_settings; | ||
logger; | ||
popupManagerLogger; | ||
_popupManager; | ||
constructor() { | ||
this.eventEmitter = new events_1.default(); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(); | ||
@@ -33,3 +37,6 @@ this.logger = (0, debug_1.initLog)('@trezor/connect-web'); | ||
manifest(data) { | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(Object.assign(Object.assign({}, this._settings), { manifest: data })); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)({ | ||
...this._settings, | ||
manifest: data, | ||
}); | ||
} | ||
@@ -50,10 +57,14 @@ dispose() { | ||
init(settings) { | ||
var _a, _b; | ||
const oldSettings = (0, connectSettings_1.parseConnectSettings)(Object.assign({}, this._settings)); | ||
const newSettings = (0, connectSettings_1.parseConnectSettings)(Object.assign(Object.assign({}, this._settings), settings)); | ||
if (!((_a = newSettings.transports) === null || _a === void 0 ? void 0 : _a.length)) { | ||
const oldSettings = (0, connectSettings_1.parseConnectSettings)({ | ||
...this._settings, | ||
}); | ||
const newSettings = (0, connectSettings_1.parseConnectSettings)({ | ||
...this._settings, | ||
...settings, | ||
}); | ||
if (!newSettings.transports?.length) { | ||
newSettings.transports = ['BridgeTransport', 'WebUsbTransport']; | ||
} | ||
newSettings.useCoreInPopup = true; | ||
if (typeof window !== 'undefined' && ((_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.origin)) { | ||
if (typeof window !== 'undefined' && window?.location?.origin) { | ||
newSettings.origin = window.location.origin; | ||
@@ -126,3 +137,2 @@ } | ||
async callInit() { | ||
var _a, _b; | ||
if (!this._popupManager) { | ||
@@ -133,3 +143,3 @@ throw ERRORS.TypedError('Init_NotInitialized'); | ||
if (this._settings.env === 'webextension') { | ||
await ((_a = this._popupManager.popupPromise) === null || _a === void 0 ? void 0 : _a.promise); | ||
await this._popupManager.popupPromise?.promise; | ||
this._popupManager.channel.postMessage({ | ||
@@ -143,8 +153,7 @@ type: events_2.POPUP.INIT, | ||
} | ||
await ((_b = this._popupManager.handshakePromise) === null || _b === void 0 ? void 0 : _b.promise); | ||
await this._popupManager.handshakePromise?.promise; | ||
} | ||
uiResponse(response) { | ||
var _a, _b; | ||
const { type, payload } = response; | ||
(_b = (_a = this._popupManager) === null || _a === void 0 ? void 0 : _a.channel) === null || _b === void 0 ? void 0 : _b.postMessage({ event: events_2.UI_EVENT, type, payload }); | ||
this._popupManager?.channel?.postMessage({ event: events_2.UI_EVENT, type, payload }); | ||
} | ||
@@ -151,0 +160,0 @@ renderWebUSBButton() { } |
@@ -12,4 +12,7 @@ "use strict"; | ||
class CoreInSuiteDesktop { | ||
eventEmitter = new events_1.default(); | ||
_settings; | ||
ws; | ||
messages; | ||
constructor() { | ||
this.eventEmitter = new events_1.default(); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(); | ||
@@ -19,9 +22,11 @@ this.messages = (0, utils_1.createDeferredManager)(); | ||
manifest(data) { | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(Object.assign(Object.assign({}, this._settings), { manifest: data })); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)({ | ||
...this._settings, | ||
manifest: data, | ||
}); | ||
} | ||
dispose() { | ||
var _a; | ||
this.eventEmitter.removeAllListeners(); | ||
this._settings = (0, connectSettings_1.parseConnectSettings)(); | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.close(); | ||
this.ws?.close(); | ||
return Promise.resolve(undefined); | ||
@@ -31,5 +36,4 @@ } | ||
async handshake() { | ||
var _a; | ||
const { promise, promiseId } = this.messages.create(1000); | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ | ||
this.ws?.send(JSON.stringify({ | ||
id: promiseId, | ||
@@ -47,9 +51,11 @@ type: events_2.POPUP.HANDSHAKE, | ||
async init(settings = {}) { | ||
var _a, _b; | ||
const newSettings = (0, connectSettings_1.parseConnectSettings)(Object.assign(Object.assign({}, this._settings), settings)); | ||
if (!((_a = newSettings.transports) === null || _a === void 0 ? void 0 : _a.length)) { | ||
const newSettings = (0, connectSettings_1.parseConnectSettings)({ | ||
...this._settings, | ||
...settings, | ||
}); | ||
if (!newSettings.transports?.length) { | ||
newSettings.transports = ['BridgeTransport', 'WebUsbTransport']; | ||
} | ||
this._settings = newSettings; | ||
(_b = this.ws) === null || _b === void 0 ? void 0 : _b.close(); | ||
this.ws?.close(); | ||
const wsOpen = (0, utils_1.createDeferred)(1000); | ||
@@ -69,3 +75,3 @@ this.ws = new WebSocket('ws://localhost:21335/connect-ws'); | ||
} | ||
catch (_a) { | ||
catch { | ||
} | ||
@@ -79,4 +85,3 @@ }); | ||
setTimeout(() => { | ||
var _a; | ||
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) { | ||
if (this.ws?.readyState === WebSocket.OPEN) { | ||
wsOpen.resolve(); | ||
@@ -93,3 +98,2 @@ } | ||
async call(params) { | ||
var _a; | ||
try { | ||
@@ -101,3 +105,3 @@ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { | ||
const { promise, promiseId } = this.messages.create(); | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ | ||
this.ws?.send(JSON.stringify({ | ||
id: promiseId, | ||
@@ -104,0 +108,0 @@ type: events_2.IFRAME.CALL, |
@@ -44,9 +44,8 @@ "use strict"; | ||
handleErrorFallback: async (errorCode) => { | ||
var _a, _b, _c, _d, _e; | ||
const env = (0, connectSettings_1.getEnv)(); | ||
const isCoreModeDisabled = ((_a = impl.lastSettings) === null || _a === void 0 ? void 0 : _a.popup) === false || env === 'webextension'; | ||
const isCoreModeAuto = ((_b = impl.lastSettings) === null || _b === void 0 ? void 0 : _b.coreMode) === 'auto' || ((_c = impl.lastSettings) === null || _c === void 0 ? void 0 : _c.coreMode) === undefined; | ||
const isCoreModeDisabled = impl.lastSettings?.popup === false || env === 'webextension'; | ||
const isCoreModeAuto = impl.lastSettings?.coreMode === 'auto' || impl.lastSettings?.coreMode === undefined; | ||
if (!isCoreModeDisabled && isCoreModeAuto && IFRAME_ERRORS.includes(errorCode)) { | ||
const webUsbUnavailableInBrowser = !(navigator === null || navigator === void 0 ? void 0 : navigator.usb); | ||
const webUsbDisabledInSettings = ((_e = (_d = impl.lastSettings) === null || _d === void 0 ? void 0 : _d.transports) === null || _e === void 0 ? void 0 : _e.includes('WebUsbTransport')) === false; | ||
const webUsbUnavailableInBrowser = !navigator?.usb; | ||
const webUsbDisabledInSettings = impl.lastSettings?.transports?.includes('WebUsbTransport') === false; | ||
if (errorCode === 'Transport_Missing' && | ||
@@ -53,0 +52,0 @@ (webUsbUnavailableInBrowser || webUsbDisabledInSettings)) { |
@@ -30,29 +30,18 @@ "use strict"; | ||
class PopupManager extends events_1.default { | ||
popupWindow; | ||
settings; | ||
origin; | ||
locked = false; | ||
channel; | ||
channelIframe; | ||
handshakePromise; | ||
iframeHandshakePromise; | ||
popupPromise; | ||
requestTimeout; | ||
openTimeout; | ||
closeInterval; | ||
extensionTabId = 0; | ||
logger; | ||
constructor(settings, { logger }) { | ||
var _a; | ||
super(); | ||
this.locked = false; | ||
this.extensionTabId = 0; | ||
this.injectContentScript = (tabId) => { | ||
chrome.permissions.getAll(permissions => { | ||
var _a; | ||
if ((_a = permissions.permissions) === null || _a === void 0 ? void 0 : _a.includes('scripting')) { | ||
(0, utils_1.scheduleAction)(() => chrome.scripting | ||
.executeScript({ | ||
target: { tabId }, | ||
func: () => { | ||
}, | ||
}) | ||
.then(() => { | ||
this.logger.debug('content script injected'); | ||
}) | ||
.catch(error => { | ||
this.logger.error('content script injection error', error); | ||
throw error; | ||
}), { attempts: new Array(3).fill({ timeout: 100 }) }); | ||
} | ||
else { | ||
} | ||
}); | ||
}; | ||
this.settings = settings; | ||
@@ -70,5 +59,4 @@ this.origin = (0, urlUtils_1.getOrigin)(settings.popupSrc); | ||
currentId: () => { | ||
var _a, _b; | ||
if (((_a = this.popupWindow) === null || _a === void 0 ? void 0 : _a.mode) === 'tab') | ||
return (_b = this.popupWindow) === null || _b === void 0 ? void 0 : _b.tab.id; | ||
if (this.popupWindow?.mode === 'tab') | ||
return this.popupWindow?.tab.id; | ||
}, | ||
@@ -82,5 +70,4 @@ legacyMode: !this.settings.useCoreInPopup, | ||
windowPeer: () => { | ||
var _a, _b; | ||
if (((_a = this.popupWindow) === null || _a === void 0 ? void 0 : _a.mode) === 'window') | ||
return (_b = this.popupWindow) === null || _b === void 0 ? void 0 : _b.window; | ||
if (this.popupWindow?.mode === 'window') | ||
return this.popupWindow?.window; | ||
}, | ||
@@ -108,3 +95,3 @@ channel: { | ||
}); | ||
(_a = this.channelIframe) === null || _a === void 0 ? void 0 : _a.on('message', this.handleMessage.bind(this)); | ||
this.channelIframe?.on('message', this.handleMessage.bind(this)); | ||
} | ||
@@ -125,5 +112,4 @@ if (this.settings.useCoreInPopup) { | ||
async request() { | ||
var _a, _b, _c, _d, _f; | ||
if (this.settings.useCoreInPopup && ((_a = this.popupWindow) === null || _a === void 0 ? void 0 : _a.mode) === 'tab') { | ||
const currentPopupExists = await checkIfTabExists((_c = (_b = this.popupWindow) === null || _b === void 0 ? void 0 : _b.tab) === null || _c === void 0 ? void 0 : _c.id); | ||
if (this.settings.useCoreInPopup && this.popupWindow?.mode === 'tab') { | ||
const currentPopupExists = await checkIfTabExists(this.popupWindow?.tab?.id); | ||
if (!currentPopupExists) { | ||
@@ -134,6 +120,6 @@ this.clear(); | ||
if (this.locked) { | ||
if (((_d = this.popupWindow) === null || _d === void 0 ? void 0 : _d.mode) === 'tab' && this.popupWindow.tab.id) { | ||
if (this.popupWindow?.mode === 'tab' && this.popupWindow.tab.id) { | ||
chrome.tabs.update(this.popupWindow.tab.id, { active: true }); | ||
} | ||
else if (((_f = this.popupWindow) === null || _f === void 0 ? void 0 : _f.mode) === 'window') { | ||
else if (this.popupWindow?.mode === 'window') { | ||
this.popupWindow.window.focus(); | ||
@@ -189,7 +175,6 @@ } | ||
buildPopupUrl(src) { | ||
var _a; | ||
const params = new URLSearchParams(); | ||
params.set('version', version_1.VERSION); | ||
params.set('env', this.settings.env); | ||
if (this.settings.env === 'webextension' && ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.id)) { | ||
if (this.settings.env === 'webextension' && chrome?.runtime?.id) { | ||
params.set('extension-id', chrome.runtime.id); | ||
@@ -207,3 +192,3 @@ params.set('cs-ver', version_1.CONTENT_SCRIPT_VERSION.toString()); | ||
chrome.tabs.query({ | ||
windowId: newWindow === null || newWindow === void 0 ? void 0 : newWindow.id, | ||
windowId: newWindow?.id, | ||
active: true, | ||
@@ -243,4 +228,24 @@ }, tabs => { | ||
} | ||
injectContentScript = (tabId) => { | ||
chrome.permissions.getAll(permissions => { | ||
if (permissions.permissions?.includes('scripting')) { | ||
(0, utils_1.scheduleAction)(() => chrome.scripting | ||
.executeScript({ | ||
target: { tabId }, | ||
func: () => { | ||
}, | ||
}) | ||
.then(() => { | ||
this.logger.debug('content script injected'); | ||
}) | ||
.catch(error => { | ||
this.logger.error('content script injection error', error); | ||
throw error; | ||
}), { attempts: new Array(3).fill({ timeout: 100 }) }); | ||
} | ||
else { | ||
} | ||
}); | ||
}; | ||
handleCoreMessage(message) { | ||
var _a; | ||
if (message.type === events_2.POPUP.BOOTSTRAP) { | ||
@@ -264,3 +269,3 @@ this.channel.init(); | ||
}); | ||
(_a = this.handshakePromise) === null || _a === void 0 ? void 0 : _a.resolve(); | ||
this.handshakePromise?.resolve(); | ||
} | ||
@@ -300,5 +305,4 @@ else if (message.type === events_2.POPUP.CLOSED) { | ||
handleMessage(data) { | ||
var _a, _b; | ||
if (data.type === events_2.IFRAME.LOADED) { | ||
(_a = this.iframeHandshakePromise) === null || _a === void 0 ? void 0 : _a.resolve(data.payload); | ||
this.iframeHandshakePromise?.resolve(data.payload); | ||
} | ||
@@ -321,6 +325,9 @@ else if (data.type === events_2.POPUP.BOOTSTRAP) { | ||
} | ||
(_b = this.iframeHandshakePromise) === null || _b === void 0 ? void 0 : _b.promise.then(payload => { | ||
this.iframeHandshakePromise?.promise.then(payload => { | ||
this.channel.postMessage({ | ||
type: events_2.POPUP.INIT, | ||
payload: Object.assign(Object.assign({}, payload), { settings: this.settings }), | ||
payload: { | ||
...payload, | ||
settings: this.settings, | ||
}, | ||
}); | ||
@@ -365,3 +372,2 @@ }); | ||
close() { | ||
var _a; | ||
if (!this.popupWindow) | ||
@@ -385,3 +391,3 @@ return; | ||
this.popupWindow = undefined; | ||
if ((_a = this.settings) === null || _a === void 0 ? void 0 : _a.useCoreInPopup) { | ||
if (this.settings?.useCoreInPopup) { | ||
this.channel.clear(); | ||
@@ -391,3 +397,2 @@ } | ||
async postMessage(message) { | ||
var _a, _b; | ||
if (!this.popupWindow && message.type !== events_2.UI.REQUEST_UI_WINDOW && this.openTimeout) { | ||
@@ -403,6 +408,6 @@ this.clear(); | ||
} | ||
if (((_a = this.popupWindow) === null || _a === void 0 ? void 0 : _a.mode) === 'window') { | ||
if (this.popupWindow?.mode === 'window') { | ||
this.popupWindow.window.postMessage(message, this.origin); | ||
} | ||
else if (((_b = this.popupWindow) === null || _b === void 0 ? void 0 : _b.mode) === 'tab') { | ||
else if (this.popupWindow?.mode === 'tab') { | ||
this.channel.postMessage(message); | ||
@@ -412,10 +417,8 @@ } | ||
isWebExtensionWithTab() { | ||
var _a; | ||
return (((_a = this.settings) === null || _a === void 0 ? void 0 : _a.env) === 'webextension' && | ||
return (this.settings?.env === 'webextension' && | ||
typeof chrome !== 'undefined' && | ||
typeof (chrome === null || chrome === void 0 ? void 0 : chrome.tabs) !== 'undefined'); | ||
typeof chrome?.tabs !== 'undefined'); | ||
} | ||
emitClosed() { | ||
var _a; | ||
if ((_a = this.settings) === null || _a === void 0 ? void 0 : _a.useCoreInPopup) { | ||
if (this.settings?.useCoreInPopup) { | ||
this.channel.resolveMessagePromises({ | ||
@@ -422,0 +425,0 @@ code: 'Method_Interrupted', |
@@ -31,3 +31,3 @@ "use strict"; | ||
} | ||
catch (_a) { | ||
catch { | ||
} | ||
@@ -34,0 +34,0 @@ } |
@@ -1,2 +0,2 @@ | ||
declare const VERSION: "9.4.8-beta.2"; | ||
declare const VERSION: "9.5.0-beta.1"; | ||
declare const versionN: number[]; | ||
@@ -3,0 +3,0 @@ declare const isBeta: boolean; |
"use strict"; | ||
const VERSION = '9.4.8-beta.2'; | ||
const VERSION = '9.5.0-beta.1'; | ||
const versionN = VERSION.split('.').map(s => parseInt(s, 10)); | ||
@@ -4,0 +4,0 @@ const isBeta = VERSION.includes('beta'); |
@@ -17,3 +17,3 @@ "use strict"; | ||
} | ||
catch (_a) { | ||
catch { | ||
} | ||
@@ -20,0 +20,0 @@ } |
{ | ||
"name": "@trezor/connect-web", | ||
"version": "9.4.8-beta.2", | ||
"version": "9.5.0-beta.1", | ||
"author": "Trezor <info@trezor.io>", | ||
@@ -45,5 +45,5 @@ "homepage": "https://github.com/trezor/trezor-suite/tree/develop/packages/connect-web", | ||
"dependencies": { | ||
"@trezor/connect": "9.4.8-beta.2", | ||
"@trezor/connect-common": "0.2.8-beta.1", | ||
"@trezor/utils": "9.2.7-beta.2" | ||
"@trezor/connect": "9.5.0-beta.1", | ||
"@trezor/connect-common": "0.3.0-beta.1", | ||
"@trezor/utils": "9.3.0-beta.1" | ||
}, | ||
@@ -65,3 +65,3 @@ "devDependencies": { | ||
"tsx": "^4.16.3", | ||
"webpack": "^5.96.1", | ||
"webpack": "^5.97.1", | ||
"webpack-cli": "^5.1.4", | ||
@@ -68,0 +68,0 @@ "webpack-merge": "^6.0.1", |
2032
97347
+ Added@trezor/blockchain-link@2.4.0-beta.1(transitive)
+ Added@trezor/blockchain-link-types@1.3.0-beta.1(transitive)
+ Added@trezor/blockchain-link-utils@1.3.0-beta.1(transitive)
+ Added@trezor/connect@9.5.0-beta.1(transitive)
+ Added@trezor/connect-common@0.3.0-beta.1(transitive)
+ Added@trezor/env-utils@1.3.0-beta.1(transitive)
+ Added@trezor/protobuf@1.3.0-beta.1(transitive)
+ Added@trezor/schema-utils@1.3.0-beta.1(transitive)
+ Added@trezor/transport@1.4.0-beta.1(transitive)
+ Added@trezor/utils@9.2.7-beta.19.3.0-beta.1(transitive)
+ Added@trezor/utxo-lib@2.3.0-beta.1(transitive)
+ Added@trezor/websocket-client@1.1.0-beta.1(transitive)
- Removed@trezor/blockchain-link@2.3.7-beta.1(transitive)
- Removed@trezor/blockchain-link-types@1.2.6-beta.1(transitive)
- Removed@trezor/blockchain-link-utils@1.2.7-beta.1(transitive)
- Removed@trezor/connect@9.4.8-beta.2(transitive)
- Removed@trezor/connect-common@0.2.8-beta.1(transitive)
- Removed@trezor/protobuf@1.2.7-beta.1(transitive)
- Removed@trezor/schema-utils@1.2.4-beta.1(transitive)
- Removed@trezor/transport@1.3.8-beta.1(transitive)
- Removed@trezor/utils@9.2.7-beta.2(transitive)
- Removed@trezor/utxo-lib@2.2.7-beta.1(transitive)
- Removed@trezor/websocket-client@1.0.1-beta.1(transitive)
Updated@trezor/connect@9.5.0-beta.1
Updated@trezor/utils@9.3.0-beta.1