浏览器设置非隐身模式

void HeadlessShell::OnBrowserStart(HeadlessBrowser* browser) {
  browser_ = browser;

#if defined(HEADLESS_USE_POLICY)
  if (policy::HeadlessModePolicy::IsHeadlessDisabled(
          static_cast<HeadlessBrowserImpl*>(browser)->GetPrefs())) {
    LOG(ERROR) << "Headless mode is disabled by policy.";
    ShutdownSoon();
    return;
  }
#endif

  file_task_runner_ = base::ThreadPool::CreateSequencedTaskRunner(
      {base::MayBlock(), base::TaskPriority::BEST_EFFORT});

  HeadlessBrowserContext::Builder context_builder =
      browser_->CreateBrowserContextBuilder();

  // Retrieve the locale set by InitApplicationLocale() in
  // headless_content_main_delegate.cc in a way that is free of side-effects.
  context_builder.SetAcceptLanguage(base::i18n::GetConfiguredLocale());
#if 0//disable incognito
  context_builder.SetIncognitoMode(false);

#endif
  browser_context_ = context_builder.Build();
  browser_->SetDefaultBrowserContext(browser_context_);

  base::CommandLine::StringVector args =
      base::CommandLine::ForCurrentProcess()->GetArgs();

  // If no explicit URL is present, navigate to about:blank, unless we're being
  // driven by a debugger.
  if (args.empty() && !IsRemoteDebuggingEnabled())
    args.push_back(kAboutBlank);

  if (!args.empty()) {
    file_task_runner_->PostTaskAndReplyWithResult(
        FROM_HERE, base::BindOnce(&ConvertArgumentToURL, args.front()),
        base::BindOnce(&HeadlessShell::OnCommandLineURL,
                       weak_factory_.GetWeakPtr()));
  }
}

设置不是隐身模式:

  context_builder.SetIncognitoMode(false);

posted @ 2024-09-24 10:37  Bigben  阅读(14)  评论(0编辑  收藏  举报