diff --git a/packages/puter-js/src/index.js b/packages/puter-js/src/index.js index 1cccd388..6c2282eb 100644 --- a/packages/puter-js/src/index.js +++ b/packages/puter-js/src/index.js @@ -112,10 +112,11 @@ window.puter = (function() { // The default APIOrigin is https://api.puter.com. However, if the URL contains a `puter.api_origin` query parameter, // then that value is used as the APIOrigin. If the URL contains a `puter.domain` query parameter, then the APIOrigin // is constructed as `https://api.`. + // This should only be done when the SDK is running in 'app' mode. this.APIOrigin = this.defaultAPIOrigin; - if(URLParams.has('puter.api_origin')){ + if(URLParams.has('puter.api_origin') && this.env === 'app'){ this.APIOrigin = decodeURIComponent(URLParams.get('puter.api_origin')); - }else if(URLParams.has('puter.domain')){ + }else if(URLParams.has('puter.domain') && this.env === 'app'){ this.APIOrigin = 'https://api.' + URLParams.get('puter.domain'); } diff --git a/src/IPC.js b/src/IPC.js index a71b2149..a5e3ffdf 100644 --- a/src/IPC.js +++ b/src/IPC.js @@ -71,7 +71,10 @@ window.addEventListener('message', async (event) => { // `appInstanceID` is required if(!event.data.appInstanceID){ - console.log(`appInstanceID is needed`); + console.error(`appInstanceID is needed`); + return; + }else if(!window.app_instance_ids.has(event.data.appInstanceID)){ + console.error(`appInstanceID is invalid`); return; } @@ -165,7 +168,6 @@ window.addEventListener('message', async (event) => { center: event.data.options.center, show_in_taskbar: event.data.options.show_in_taskbar, iframe_srcdoc: event.data.options.content, - iframe_url: event.data.options.url, parent_uuid: event.data.appInstanceID, }) } diff --git a/src/globals.js b/src/globals.js index ea429a28..3860f921 100644 --- a/src/globals.js +++ b/src/globals.js @@ -24,6 +24,7 @@ window.window_nav_history = {}; window.window_nav_history_current_position = {}; window.progress_tracker = []; window.upload_item_global_id = 0; +window.app_instance_ids = new Set(); window.download_progress = []; window.download_item_global_id = 0; diff --git a/src/helpers.js b/src/helpers.js index f912f1b8..7b3ecfed 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1762,6 +1762,10 @@ window.launch_app = async (options)=>{ // ...and finally append utm_source=puter.com to the URL iframe_url.searchParams.append('utm_source', 'puter.com'); + // register app_instance_uid + window.app_instance_ids.add(uuid); + + // open window el_win = UIWindow({ element_uuid: uuid, title: title,