question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REGRESSION]: Types for BrowserTypeLaunchOptions and BrowserContextCookies are not exported

See original GitHub issue

Context:

  • GOOD Playwright Version: 0.12.1
  • BAD Playwright Version: 0.13.0

Code Snippet

import { BrowserContextCookies, BrowserTypeLaunchOptions } from 'playwright';

Describe the bug

These types are no longer available.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
JoelEinbindercommented, Apr 9, 2020

For one-off use cases, you can still get the types by using TypeScript’s Parameters type.

async function myFunction(page: import('playwright').Page, options: Parameters<typeof page.goto>[1]) {
  await page.goto('https://example.com', options);
}

This has the benefit of being guaranteed to work forever, even if the signature of page.goto changes. The downside is that it looks fairly ugly.

With the previous types, we were generating and exporting all of the object types inside of the api. The upside of this is that you get everything. The downsides are that there is a lot of useless types adding noise to the API, and it options us up to introducing subtle breaking changes.

PageGotoOptions and FrameGotoOptions, are identical. If we merged them, into GotoOptions, someone might write code like:

const opt: GotoOptions = ...;
await page.goto(opt);
await frame.goto(opt);

Then, if we later added a new option foo to page.goto, but did not add foo to frame.goto, it would be a breaking change. We could solve this by having GotoOptions contain the shared options contained by page.goto and frame.goto, and then having PageGotoOptions extend GotoOptions with the same type. This makes our generating process significantly more complicated, because we would need to check not just whether types can be merged, but if and how they were merged in a previously released version of playwright.

Perhaps a bigger subtle problem with exporting all of the types was that we add the parameter name into the type name. BrowserTypeLaunchOptions ends with Options because the first argument to browserType.launch is options. If we were to rename browserType.launch(options) into browserType.launch(nameOrOptions) or browserType.launch(opt), this usually wouldn’t be a breaking change. But with the generated types it is, because the type name will change.

Ways to proceed:

  1. Leave things as they are, manually pick out parameters with Parameters.
  2. Put back all of the generated types. Create a system that yells when something goes wrong, and then we will manually fix problems by aliasing types.
  3. Whitelist some generated types or manually add some types that feel both safe and useful.
  4. Create a new endpoint, playwright/types, that contains the types. This might have a different stability contract, where we don’t consider changes here to be breaking.

What do you all think?

0reactions
ghscommented, Jul 15, 2020

I’ve opened another issue some days ago, https://github.com/microsoft/playwright/issues/2752, but while searching another thing ended up here. Thanks for the clarification! Just in case, from historical reason from pptr, we use also: ElementHandleScreenshotOptions, PageGotoOptions, PageScreenshotOptions.

This one as well: BrowserTypeLaunchServerOptions

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] browserContext.cookies() doesn't return all ... - GitHub
[BUG] browserContext.cookies() doesn't return all cookies #12967 ... module.exports = async (config) => { const browser = await ...
Read more >
Changelog - Cypress Documentation
Caching and restoring cookies, localStorage , and sessionStorage between tests; Configuring testIsolation in suites to define whether or not the browser context ......
Read more >
Why can't I get cookie value in Playwright? - Stack Overflow
In your second method, change cookies = context.cookies to cookies = context.cookies() . It's a method, you need to call it.
Read more >
BrowserType (Playwright - Main Library 1.22.0 API) - javadoc.io
Browser · launch(BrowserType.LaunchOptions options). Returns the browser instance. ; default BrowserContext · launchPersistentContext(Path userDataDir). Returns ...
Read more >
Playwright.BrowserContext — playwright v1.18.0-alpha.1
create a new "incognito" browser context: context = Playwright. ... Register a (non-blocking) callback/handler for various types of events. pages(context).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found