Skip to content

feat: add hidden browser window for execution [INS-3378]#6897

Closed
ihexxa wants to merge 28 commits intodevelopfrom
feat-sandbox
Closed

feat: add hidden browser window for execution [INS-3378]#6897
ihexxa wants to merge 28 commits intodevelopfrom
feat-sandbox

Conversation

@ihexxa
Copy link
Contributor

@ihexxa ihexxa commented Dec 4, 2023

Changes:

  • add a hidden browser window for running scripts
  • enable basic inso fields:
    • variables
    • collectionVariables
    • environment
    • iterationData
    • info
  • Add tests or checking APIs of above objects.

How to play with it:

  • In the main renderer dev tool console, start the hidden window: await window.hiddenBrowserWindow.start();
  • run some scripts
window.postMessage(
    {
      action: 'message-event://hidden.browser-window/debug',
      id: 'simply updating enviroment',
      code: `
        insomnia.environment.set('hello', 'insomnia');
        // or other code
      `,
      context: {
        insomnia: {
          environment: {
            hello: 'world',
          },            
        },
      },
    },
    '*',
    [],
); 

TODO:

  • improve the visibility of hidden browser window procedure
  • improve the page waiting logic in test.ts
  • expose insomnia object for testing if possible

@ihexxa ihexxa marked this pull request as draft December 4, 2023 10:09
@ihexxa ihexxa self-assigned this Dec 4, 2023
@ihexxa ihexxa changed the title feat: enable islated utility process [INS-3378] feat: enable isolated utility process [INS-3378] Dec 4, 2023
@marckong
Copy link
Contributor

marckong commented Dec 8, 2023

FYI - Electron supports utility process out of the box now - https://www.electronjs.org/docs/latest/api/utility-process

We can take a look at Bloom's implementation. Theirs is pretty straightforward and clean - https://github.com/bloomwalletio/bloom/blob/f69868fc7003248fadb583d3a03a162d5f6d289b/packages/desktop/lib/electron/processes/main.process.ts#L287

@ihexxa
Copy link
Contributor Author

ihexxa commented Dec 11, 2023

@marckong Cool, how does it handle Node APIs? Let's have a discussion.

@ihexxa ihexxa requested a review from a team December 14, 2023 10:29
@ihexxa ihexxa marked this pull request as ready for review December 14, 2023 10:32
async (tc: any) => {
window.postMessage(
{
action: 'message-event://utility.process/debug',
Copy link
Contributor Author

@ihexxa ihexxa Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message names are basically named in this way protocol://target/action and it might help to understand the workflow.

Copy link
Contributor

@jackkav jackkav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide reference documentation for the utility process implementation?
The why of the PR is not particularly clear in the description, so it would be helpful for the future maintainers to list a few thoughts about why you chose this approach and what else you considered.

@ihexxa
Copy link
Contributor Author

ihexxa commented Dec 18, 2023

@jackkav It makes sense, I have one and let me update it.

@ihexxa ihexxa changed the title feat: enable isolated utility process [INS-3378] feat: add hidden browser window for execution [INS-3378] Dec 20, 2023
@jackkav
Copy link
Contributor

jackkav commented Jan 3, 2024

TODO: (perhaps out of scope) what happens when the hidden window is closed unexpectedly

Copy link
Contributor

@jackkav jackkav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an idea for exposing the issues with hidden browser window, would be to allow the insomnia object to be useable inside an insomnia test. That was we can send some simple calculation over the message port in this scope and playwright test it.

code: string,
context: object,
): Promise<RawObject | undefined> => {
if (!this.hiddenBrowserWindowPort) {
Copy link
Contributor Author

@ihexxa ihexxa Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jackkav Hidden window health checking is a good point. Current implementation mainly takes care it by following parts:

It is an interesting topic let me know if you have thoughts on it and we can have a discussion.

@jackkav jackkav marked this pull request as draft February 5, 2024 10:05
@jackkav
Copy link
Contributor

jackkav commented Feb 9, 2024

This PR was broken down into separate PRs #7063 #7070 #7065 Thanks @ihexxa really cool work!

@jackkav jackkav closed this Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants