Skip to content

Remove renderer dependency from script execution#9892

Draft
jackkav wants to merge 1 commit intoKong:developfrom
jackkav:fix/remove-renderer-script-execution
Draft

Remove renderer dependency from script execution#9892
jackkav wants to merge 1 commit intoKong:developfrom
jackkav:fix/remove-renderer-script-execution

Conversation

@jackkav
Copy link
Copy Markdown
Contributor

@jackkav jackkav commented May 5, 2026

Summary

  • inject timeline appends into runScript() so the Node/main-process runner no longer depends on renderer APIs
  • branch script execution in the concurrency and cancellation paths so main process uses direct Node execution while renderer keeps the hidden window path
  • use fs.promises.appendFile for main-process timeline writes where script execution logs are persisted

Why

This removes the remaining renderer-only dependency from the Node.js script execution path, which unblocks main-process and inso script execution without window.main.

Validation

  • npm test -w packages/insomnia -- src/network/__tests__/network.test.ts
  • npm run type-check -w packages/insomnia (blocked by existing worktree/setup issue resolving @react-router/fs-routes, unrelated to this branch)

- script-executor.ts: accept appendTimelineEntry callback instead of
  calling appendFile directly; callers supply the write implementation
- cancellation.ts: pass fs.promises.appendFile wrapper as
  appendTimelineEntry in the main-process branch of cancellableRunScript
- concurrency.ts: add process.type fork in asyncWorker; renderer path
  keeps window.main.hiddenBrowserWindow.runScript, main-process path
  calls runScript directly with appendFile callback
- network.ts: add fs.promises.appendFile fallback in tryToExecuteScript
  when runtime is not provided and process.type !== 'renderer'

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 5, 2026 15:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the remaining renderer-only dependency from the Node/main-process script execution path by injecting timeline writes into the Node runner and branching execution so non-renderer contexts can run scripts without window.main.

Changes:

  • Updated the Node/main runScript() implementation to accept an injected timeline append function (instead of calling renderer APIs / directly depending on renderer-side behavior).
  • Updated concurrency + cancellation script execution to choose between hidden-window execution (renderer) and direct Node execution (non-renderer), including persisting timeline logs via appendFile.
  • Added a fallback in tryToExecuteScript() to persist script logs directly to the timeline file in non-renderer contexts when no runtime is provided.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/insomnia/src/script-executor.ts Makes Node-runner timeline persistence injectable to remove renderer coupling.
packages/insomnia/src/network/network.ts Adds non-renderer fallback for persisting script logs when runtime isn’t present.
packages/insomnia/src/network/concurrency.ts Branches script execution between hidden-window (renderer) and direct Node execution with timeline writes.
packages/insomnia/src/network/cancellation.ts Routes non-renderer cancellation-path script execution through direct Node runner with timeline writes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 15 to +22
export const runScript = async ({
script,
context,
appendTimelineEntry,
}: {
script: string;
context: RequestContext;
appendTimelineEntry: (opts: { timelinePath: string; data: string }) => Promise<void>;
@jackkav jackkav marked this pull request as draft May 5, 2026 18:43
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.

2 participants