{"record":{"id":"c9ede55ca2009dd6","repo":"nwjs/nw.js","slug":"mixed-context-should-be-set-with-new-instance-in-n","errorCode":null,"errorMessage":"mixed_context should be set with new_instance in nw.Window.open","messagePattern":"mixed_context should be set with new_instance in nw\\.Window\\.open","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_newwin.js","lineNumber":818,"sourceCode":"      if (params['always_on_top'] === true)\n        options.alwaysOnTop = true;\n      if (params['visible_on_all_workspaces'] === true)\n        options.allVisible = true;\n      if (typeof params['inject_js_start'] == 'string')\n         options.inject_js_start = params['inject_js_start'];\n      if (typeof params['inject_js_end'] == 'string')\n         options.inject_js_end = params['inject_js_end'];\n      if (params.transparent)\n         options.alphaEnabled = true;\n      // if (params.kiosk === true)\n      //   options.kiosk = true;\n      if (params.new_instance === true) {\n        options.new_instance = true;\n        options.setSelfAsOpener = false;\n      }\n      if (params.mixed_context === true) {\n        if (params.new_instance !== true) {\n          throw new Error('mixed_context should be set with new_instance in nw.Window.open');\n        }\n        options.mixed_context = true;\n      }\n      if (params.position)\n        options.position = params.position;\n      if (params.title)\n        options.title = params.title;\n      if (params.icon)\n        options.icon = params.icon;\n      if (params.id)\n        options.id = params.id;\n    }\n    if (callback && !(options.new_instance === true) && !url.startsWith('chrome:'))\n      options.block_parser = true;\n    try_hidden(window).chrome.windows.create(options, function(cWin) {\n      try {\n        if (callback) {\n          if (cWin)","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_newwin.js#L800-L836","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add new_instance: true alongside mixed_context: true in the same params object passed to nw.Window.open().","If you do not need a separate browser instance, remove mixed_context from params entirely.","Double-check that new_instance is literally the boolean true (not a truthy string/number), since the guard uses strict !== true."],"exampleFix":"// before\nnw.Window.open('child.html', { mixed_context: true });\n// after\nnw.Window.open('child.html', { mixed_context: true, new_instance: true });","handlingStrategy":"validation","validationCode":"// before calling nw.Window.open\nif (params && params.mixed_context === true && params.new_instance !== true) {\n  throw new Error('mixed_context requires new_instance: true');\n}\nnw.Window.open(url, params, callback);","typeGuard":"function isOpenParamsSafe(params) {\n  if (!params) return true;\n  if (params.mixed_context === true && params.new_instance !== true) return false;\n  return true;\n}","tryCatchPattern":"try {\n  nw.Window.open(url, params, cb);\n} catch (e) {\n  if (e.message.includes('mixed_context')) {\n    params.new_instance = true;\n    nw.Window.open(url, params, cb);\n  } else throw e;\n}","preventionTips":["Always set new_instance whenever you set mixed_context.","Centralize window-opening in a helper that enforces the pairing.","Treat mixed_context as an advanced option and document its prerequisites in your wrapper."],"tags":["nwjs","window","api-misuse","mixed-context"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}