nwjs/nw.js · error · Error

mixed_context should be set with new_instance in nw.Window.o

Error message

mixed_context should be set with new_instance in nw.Window.open

What it means

Thrown by nw.Window.open() when the params object sets mixed_context=true but does not also set new_instance=true. The mixed_context option makes a newly opened window share the same Node/JS context as the opener, but this is only meaningful when the window is created as a fresh browser instance (new_instance=true), which also disables setSelfAsOpener. The guard enforces that these two options are always supplied together.

Source

Thrown at src/resources/api_nw_newwin.js:818

      if (params['always_on_top'] === true)
        options.alwaysOnTop = true;
      if (params['visible_on_all_workspaces'] === true)
        options.allVisible = true;
      if (typeof params['inject_js_start'] == 'string')
         options.inject_js_start = params['inject_js_start'];
      if (typeof params['inject_js_end'] == 'string')
         options.inject_js_end = params['inject_js_end'];
      if (params.transparent)
         options.alphaEnabled = true;
      // if (params.kiosk === true)
      //   options.kiosk = true;
      if (params.new_instance === true) {
        options.new_instance = true;
        options.setSelfAsOpener = false;
      }
      if (params.mixed_context === true) {
        if (params.new_instance !== true) {
          throw new Error('mixed_context should be set with new_instance in nw.Window.open');
        }
        options.mixed_context = true;
      }
      if (params.position)
        options.position = params.position;
      if (params.title)
        options.title = params.title;
      if (params.icon)
        options.icon = params.icon;
      if (params.id)
        options.id = params.id;
    }
    if (callback && !(options.new_instance === true) && !url.startsWith('chrome:'))
      options.block_parser = true;
    try_hidden(window).chrome.windows.create(options, function(cWin) {
      try {
        if (callback) {
          if (cWin)

View on GitHub (pinned to e15da848e9)

Solutions

  1. Add new_instance: true alongside mixed_context: true in the same params object passed to nw.Window.open().
  2. If you do not need a separate browser instance, remove mixed_context from params entirely.
  3. Double-check that new_instance is literally the boolean true (not a truthy string/number), since the guard uses strict !== true.

Example fix

// before
nw.Window.open('child.html', { mixed_context: true });
// after
nw.Window.open('child.html', { mixed_context: true, new_instance: true });
Defensive patterns

Strategy: validation

Validate before calling

// before calling nw.Window.open
if (params && params.mixed_context === true && params.new_instance !== true) {
  throw new Error('mixed_context requires new_instance: true');
}
nw.Window.open(url, params, callback);

Type guard

function isOpenParamsSafe(params) {
  if (!params) return true;
  if (params.mixed_context === true && params.new_instance !== true) return false;
  return true;
}

Try / catch

try {
  nw.Window.open(url, params, cb);
} catch (e) {
  if (e.message.includes('mixed_context')) {
    params.new_instance = true;
    nw.Window.open(url, params, cb);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling nw.Window.open(url, { mixed_context: true }) without also passing new_instance: true. Passing { mixed_context: true, new_instance: false } explicitly also triggers it since the check is params.new_instance !== true.

Common situations: Copying mixed_context from an NW.js v0.12 config without reading the migration notes; setting mixed_context expecting shared globals but forgetting that new_instance is a hard prerequisite; passing a dynamically-built params object where new_instance was conditionally omitted.

Related errors


AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13). Data as JSON: /api/errors/c9ede55ca2009dd6. Report an issue: GitHub.