From f468df44f42bfbf90a4bc0d5d600aa7b032d1068 Mon Sep 17 00:00:00 2001 From: Ruslan Zavacky Date: Wed, 22 Nov 2023 20:18:31 +0200 Subject: [PATCH] chore: when app runs without iframe, connect fails Let's allow for connect to finish, even if connections couldn't be established with main thread. --- .changeset/neat-apples-complain.md | 5 +++++ src/api.ts | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .changeset/neat-apples-complain.md diff --git a/.changeset/neat-apples-complain.md b/.changeset/neat-apples-complain.md new file mode 100644 index 0000000..f7eccb9 --- /dev/null +++ b/.changeset/neat-apples-complain.md @@ -0,0 +1,5 @@ +--- +'@crowdstrike/foundry-js': minor +--- + +Connect message can be undefined, if app runs without iframe. If that happens, we'll gracefully ignore failure and allow application to continue to work. diff --git a/src/api.ts b/src/api.ts index beb46d8..f533696 100644 --- a/src/api.ts +++ b/src/api.ts @@ -93,15 +93,20 @@ export default class FalconApi { * This establishes a connection to send messages between the extension and the Falcon Console. Only when established you will be able to call other APIs. */ public async connect(): Promise { - const { origin, data } = await this.bridge.postMessage({ type: 'connect' }); + const response = await this.bridge.postMessage({ type: 'connect' }); - this.bridge.setOrigin(origin); - this.data = data; + if (response !== undefined) { + let { origin, data } = response; - this.updateTheme(data?.theme); - this.resizeTracker = new ResizeTracker(this.bridge); + this.bridge.setOrigin(origin); + this.data = data; + + this.updateTheme(data?.theme); - this.isConnected = true; + this.isConnected = true; + } + + this.resizeTracker = new ResizeTracker(this.bridge); } /**