Closed silverwind closed 3 weeks ago
@silverwind for your scenario, we recommend removing the screen
property.
Investigation notes:
DeviceDescriptor
types as of todaydevices[iPhone]
but we don't take it into accountBrowser.newContext
, then we will take it into account.Proposals:
screen
property in the DeviceDescriptor
typesTo explain my use case: I'm in a library that provides the playwright config and want to avoid the @playwright/test
runtime dependency so I just extract the one browser object I need from the module so that the config becomes pure JSON:
cat node_modules/playwright-core/lib/server/deviceDescriptorsSource.json | jq '.["Desktop Chrome"]' > chrome.json
This JSON object is then imported and passed the projects.use
option. While I could filter out the screen
property in this export, I think playwright would be better off when it's own exports match its own schema.
If typescript would be more thourough in type checking the object, it would actually raise an error in the basic config because the value of devices['Desktop Chrome']
violates the type for project.use
.
I see. This sounds like it is outside of the scope for Playwright, you should be able to filter out the property during your json processing.
I see. This sounds like it is outside of the scope for Playwright, you should be able to filter out the property during your json processing.
I already have a workaround in place, but it's still a bug in Playwright that the exported object does not match the exported type.
Version
1.45.0
Steps to reproduce
npm i && npx tsc
Expected behavior
No error
Actual behavior
Typescript error:
Additional context
The object in use is a copy of what
@playwright/test
currently exports asdevices["Desktop Chrome"]
:screen
needs to be either removed if it's unused or be added to PlaywrightTestOptions.Environment