code: def _run_in_browser(
      engine: list[str],
      url: str,
      local_wait: int | None = None,
      global_wait: int | None = None,
  ) -> JSResult:
      """
      wait is in milliseconds
      """
      cmd = [*engine, url]
      if local_wait is not None:
          cmd += [str(local_wait)]
      if global_wait is not None:
          cmd += [str(global_wait)]
      trace(f"Running command: {' '.join(cmd)}")
  
      env = os.environ.copy()
      env["NODE_PATH"] = join(TOP_PATH, "bokehjs", "node_modules")
  
      try:
          proc = subprocess.Popen(
              cmd,
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE,
              env=env,
          )
      except OSError as e:
          fail(f"Failed to run: {' '.join(cmd)}")
          fail(str(e))
          sys.exit(1)
  
      with proc:
          (stdout, stderr) = proc.communicate()
  
          if proc.returncode != 0:
              output = stderr.decode("utf-8")
              fail(output)
              sys.exit(1)
  
      output = stdout.decode("utf-8")
      return json.loads(output)
  
file_path: bokeh/tests/support/util/screenshot.py
imports: from __future__ import annotations
  import logging
  import json
  import os
  import subprocess
  import sys
  from os.path import abspath, dirname, join, pardir, split
  from typing import TypedDict
  from bokeh.util.terminal import fail, trace
label_desc: Use image node_id 3 for calling a global function with example usage: _run_in_browser(engine, url, local_wait, global_wait) and returns: json