Skip to content

Instantly share code, notes, and snippets.

@saikrishna321
Last active January 12, 2020 19:40
Show Gist options
  • Save saikrishna321/927e87e06cdb3f13c46b7313c67df911 to your computer and use it in GitHub Desktop.
Save saikrishna321/927e87e06cdb3f13c46b7313c67df911 to your computer and use it in GitHub Desktop.
printWidth
@saikrishna321
Copy link
Author

const createBrowserContext = async (
  browser,
  url,
  runtimeHandler,
  options,
) => {
  _target = browser.Target;

  if (options.incognito) {
    const { browserContextId } = await _target.createBrowserContext();
    openWindowOptions = {
      url,
      browserContextId,
    };
    const { targetId } = await _target.createTarget(
      openWindowOptions,
    );
    activeTargetId = targetId;
  } else {
    await runtimeHandler.runtimeEvaluate(
      `window.open("${url}", '', 'resizable')`,
    );
    eventHandler.emit('windowOpen', _target);
    const targets = await _target.getTargets();
    activeTargetId = targets.targetInfos[0].targetId;
  }
  contexts.set(options.name, activeTargetId);
  return activeTargetId;
};

const createBrowserContext = async (browser, url, runtimeHandler, options) => {
  _target = browser.Target;

  if (options.incognito) {
    const { browserContextId } = await _target.createBrowserContext();
    openWindowOptions = {
      url,
      browserContextId,
    };
    const { targetId } = await _target.createTarget(openWindowOptions);
    activeTargetId = targetId;
  } else {
    await runtimeHandler.runtimeEvaluate(`window.open("${url}", '', 'resizable')`);
    eventHandler.emit('windowOpen', _target);
    const targets = await _target.getTargets();
    activeTargetId = targets.targetInfos[0].targetId;
  }
  contexts.set(options.name, activeTargetId);
  return activeTargetId;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment