Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 0.15 Cannot launch new chromium context after closing old one #1962

Closed
alexduhanov opened this issue Apr 24, 2020 · 10 comments
Closed

Comments

@alexduhanov
Copy link

alexduhanov commented Apr 24, 2020

Context:

  • Playwright Version: 0.15.0
  • Operating System: macOS 10.15.4

Code Snippet

let browser;

beforeAll(async () => {
  browser = await playwright['chromium'].launch({
    headless: false,
  });
});

afterAll(async () => {
  await browser.close();
});

test('1', async () => {
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('http://www.example.com');
  await context.close();
});

test('2', async () => {
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('http://www.example.com');
  await context.close();
});

Describe the bug

Error output:

    Protocol error (Target.createBrowserContext): Target closed.

      32 |     await context.close();
      33 |
    > 34 |     const context2 = await browser.newContext();
         |                                    ^
      35 |
      36 |     const page2 = await context2.newPage();
      37 |

      at Promise (node_modules/playwright-core/lib/chromium/crConnection.js:130:63)
      at CRSession.send (node_modules/playwright-core/lib/chromium/crConnection.js:129:16)
      at CRSession.<anonymous> (node_modules/playwright-core/lib/helper.js:64:31)
      at CRBrowser.newContext (node_modules/playwright-core/lib/chromium/crBrowser.js:93:58)
      at CRBrowser.newContext (node_modules/playwright-core/lib/helper.js:64:31)
      at _callee3$ (tests/playwright/login.test.js:34:36)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:274:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
      at asyncGeneratorStep (tests/playwright/login.test.js:11:103)
      at _next (tests/playwright/login.test.js:13:194)

This does seems to work for webkit and firefox.

Not sure if I'm doing something wrong -- I did see this note in the docs: the default browser context cannot be closed. but it wasn't clear to me if this meant "you cannot close the first new context you create via invoking newContext()" or "you cannot close a context if you do not invoke newContext() at all".

Thanks!

@mxschmitt
Copy link
Member

Which operating system / Linux distribution are you using?

@alexduhanov
Copy link
Author

alexduhanov commented Apr 24, 2020

Sorry - meant macOS 10.15.4

@sagrawal-idrc
Copy link

sagrawal-idrc commented Apr 25, 2020

I am having a somewhat related (?) error after upgrading from 0.13.0 to 0.15.0.

Using chromium for testing on Ubuntu 18.04.4 LTS.

The tests which were working well earlier, have started having this error now:

Error: Protocol error (Target.createBrowserContext): Target closed.

before, after hooks are as under:

beforeAll(async () => {
  browser = await chromium.launch({ headless: false });
  // custom function
  teamMembers = await getTeamMembersDataFromMdFiles();
});

beforeEach(async () => {
  browserContext = await browser.newContext();
  page = await browserContext.newPage();

  await page.goto(`${appUrl}/`);
});

afterEach(async () => {
    await page.close();
    await browserContext.close();
});

afterAll(async () => {
  await browser.close();
});

If this error is not related, apologies; please let me know. I will create another ticket.

Edit: Working fine for firefox.

@pavelfeldman
Copy link
Member

Your code snippets look good, so there is something wrong with either the test harness or with Playwright. Our tests do the same thing and they pass. Could you share an end-to-end snippet or a repo where this would reproduce? That would help a lot.

@sagrawal-idrc
Copy link

sagrawal-idrc commented Apr 26, 2020

Here's an example. Following example works for:

  • Firefox
  • Webkit
  • On Chromium, when either test is run individually.

Breaks on Chromium, trying to run both tests together. Error (before second test):

Protocol error (Target.createBrowserContext): Target closed.

      12 | 
      13 | beforeEach(async () => {
    > 14 |   browserContext = await browser.newContext();
         |                                  ^
      15 |   page = await browserContext.newPage();
      16 | 
      17 |   await page.goto(`${appUrl}/`);

      at node_modules/playwright-core/lib/chromium/crConnection.js:130:63

Playwright: 0.15.0
jest: 25.3.0
OS: Ubuntu 18.04.4 LTS

const { chromium } = require('playwright');

const appUrl = 'http://example.com/';

let page;
let browserContext;
let browser;

beforeAll(async () => {
  browser = await chromium.launch({ headless: false });
});

beforeEach(async () => {
  browserContext = await browser.newContext();
  page = await browserContext.newPage();

  await page.goto(`${appUrl}/`);
});

afterEach(async () => {
  if (!page.isClosed()) {
    await page.close();
    await browserContext.close();
  }
});

afterAll(async () => {
  await browser.close();
});

describe('Home Page', () => {
  it('should have the correct title', async () => {
    await page.waitForSelector('text=Example Domain');
    const pageTitle = await page.title();
    expect(pageTitle).toBe('Example Domain');
  });

  it('should have the correct text in link', async () => {
    const tagEl = await page.waitForSelector('a');
    const tagText = await tagEl.evaluate((el) => el.innerText);
    expect(tagText).toBe('More information...');
  });
});

Edit: Just checked, this works good for 0.13.0 and 0.14.0.

@alexduhanov
Copy link
Author

@pavelfeldman I've created a minimal standalone project you can check out that incorporates my snippet:

https://github.com/alexduhanov/playwright-test

Both tests in the suite pass individually but running the suite results in the Target closed error mentioned above.

@alexduhanov
Copy link
Author

Out of curiosity I ran my example snippet in headless mode, and the tests succeeded. It seems like the problem may be tied to disabling chromium headless mode, which is also consistent with the example @sagrawal-idrc posted.

@yury-s
Copy link
Member

yury-s commented Apr 27, 2020

Thanks for the great example, I managed to reproduce it locally in headful mode (headless seems to be fine). In headful mode the browser crashes:

pw:browser:err Received signal 11 SEGV_MAPERR ffffd2fb3eb2afdf +301ms
pw:browser:err #0 0x55cedd8ae919 base::debug::CollectStackTrace() +10ms
pw:browser:err #1 0x55cedd813723 base::debug::StackTrace::StackTrace() +8ms
pw:browser:err #2 0x55cedd8ae4b5 base::debug::(anonymous namespace)::StackDumpSignalHandler() +7ms
pw:browser:err #3 0x7f097decf890 (/lib/x86_64-linux-gnu/libpthread-2.27.so+0x1288f) +0ms
pw:browser:err #4 0x55cedd6130ff SharingServiceFactory::GetBrowserContextToUse() +5ms
pw:browser:err #5 0x55cede832d00 KeyedServiceFactory::GetServiceForContext() +8ms
pw:browser:err #6 0x55cedd7fbde6 SessionServiceFactory::GetForProfile() +5ms
pw:browser:err #7 0x55cedff1facc Browser::~Browser() +11ms
pw:browser:err #8 0x55cedff201be Browser::~Browser() +10ms
pw:browser:err #9 0x55cee00ccaba BrowserView::~BrowserView() +12ms
pw:browser:err #10 0x55cee00ccd95 BrowserView::~BrowserView() +11ms
pw:browser:err #11 0x55cedf6edbaf views::View::~View() +9ms
pw:browser:err #12 0x55cedf71accd views::NonClientView::~NonClientView() +10ms
pw:browser:err #13 0x55cedf6ee9b7 views::View::DoRemoveChildView() +9ms
pw:browser:err #14 0x55cedf6eea05 views::View::RemoveAllChildViews() +9ms
pw:browser:err #15 0x55cedf705cbf views::Widget::~Widget() +10ms
pw:browser:err #16 0x55cee00da13c BrowserFrame::~BrowserFrame() +11ms
pw:browser:err #17 0x55cee00da1ae BrowserFrame::~BrowserFrame() +11ms
pw:browser:err #18 0x55cedf736717 views::DesktopNativeWidgetAura::~DesktopNativeWidgetAura() +10ms
pw:browser:err #19 0x55cee0119aeb DesktopBrowserFrameAuraLinux::~DesktopBrowserFrameAuraLinux() +11ms
pw:browser:err #20 0x55cedf743b3f views::DesktopWindowTreeHostPlatform::OnClosed() +10ms
pw:browser:err #21 0x55cedf72acd5 views::DesktopWindowTreeHostLinux::OnClosed() +9ms
pw:browser:err #22 0x55cedf741cf8 views::DesktopWindowTreeHostPlatform::CloseNow() +10ms
pw:browser:err #23 0x55cedd85b5ab base::TaskAnnotator::RunTask() +5ms
pw:browser:err #24 0x55cedd86b648 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl() +6ms
pw:browser:err #25 0x55cedd86b3e8 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() +5ms
pw:browser:err #26 0x55cedd827eca base::MessagePumpGlib::Run() +6ms
pw:browser:err #27 0x55cedd86bbf5 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run() +5ms
pw:browser:err #28 0x55cedd844fbe base::RunLoop::Run() +6ms
pw:browser:err #29 0x55cedd486d93 ChromeBrowserMainParts::MainMessageLoopRun() +5ms
pw:browser:err #30 0x55cedbb72bab content::BrowserMainLoop::RunMainMessageLoopParts() +2ms
pw:browser:err #31 0x55cedbb74a72 content::BrowserMainRunnerImpl::Run() +1ms
pw:browser:err #32 0x55cedbb6fcad content::BrowserMain() +2ms
pw:browser:err #33 0x55cedd4080d6 content::ContentMainRunnerImpl::RunServiceManager() +5ms
pw:browser:err #34 0x55cedd407d07 content::ContentMainRunnerImpl::Run() +5ms
pw:browser:err #35 0x55cedd467c29 service_manager::Main() +5ms
pw:browser:err #36 0x55cedd405f51 content::ContentMain() +4ms
pw:browser:err #37 0x55cedae5266e ChromeMain +16ms
pw:browser:err #38 0x7f097783ab97 __libc_start_main +0ms
pw:browser:err #39 0x55cedae524aa _start +16ms

I'll look at what's going on there.

@yury-s
Copy link
Member

yury-s commented Apr 27, 2020

Minimal repro case:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({
    headless: false,
  });
  const context = await browser.newContext();
  await context.newPage();
  await context.close();
})();

@yury-s
Copy link
Member

yury-s commented Apr 28, 2020

Fixing upstream in https://chromium-review.googlesource.com/c/chromium/src/+/2168515

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants