Comments (5)
I am digging into this issue some more to try and figure out if there is a difference between None
and False
.
It appears that chromium_sandbox
will be passed to the launch
and lanuch_persistent_context
methods of BrowserType
as the chromiumSandbox
parameter, which is declared as a bool
but defaults to None
.
The more I look, I see None
being declared as the default when the parameter/attribute isn't declared as optional, a different but related issue to the one at hand (e.g. all the methods in BrowserType
).
@jamesbraza your report appears to just be the tip of the iceberg.
from playwright-python.
Great, I agree!
Regarding the other issue at hand, observe the Browser
method:
class Browser(ChannelOwner):
...
async def new_context(
self,
viewport: ViewportSize = None,
screen: ViewportSize = None,
noViewport: bool = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
bypassCSP: bool = None,
userAgent: str = None,
locale: str = None,
timezoneId: str = None,
geolocation: Geolocation = None,
permissions: Sequence[str] = None,
extraHTTPHeaders: Dict[str, str] = None,
offline: bool = None,
httpCredentials: HttpCredentials = None,
deviceScaleFactor: float = None,
isMobile: bool = None,
hasTouch: bool = None,
colorScheme: ColorScheme = None,
reducedMotion: ReducedMotion = None,
forcedColors: ForcedColors = None,
acceptDownloads: bool = None,
defaultBrowserType: str = None,
proxy: ProxySettings = None,
recordHarPath: Union[Path, str] = None,
recordHarOmitContent: bool = None,
recordVideoDir: Union[Path, str] = None,
recordVideoSize: ViewportSize = None,
storageState: Union[StorageState, str, Path] = None,
baseURL: str = None,
strictSelectors: bool = None,
serviceWorkers: ServiceWorkersPolicy = None,
recordHarUrlFilter: Union[Pattern[str], str] = None,
recordHarMode: HarMode = None,
recordHarContent: HarContentPolicy = None,
) -> BrowserContext:
...
The type-hints for the new_context
parameters are incorrect, namely, None
is being used as the default despite the parameter not being declared as optional. This occurs in a lot of other areas in the code base. I realize Python typing is very optional, but I figure that if we use type hints we might as well use them properly.
An update that is compliant with Python 3.9- may look like this:
class Browser(ChannelOwner):
...
async def new_context(
self,
viewport: Optional[ViewportSize] = None,
screen: Optional[ViewportSize] = None,
noViewport: Optional[bool] = None,
ignoreHTTPSErrors: Optional[bool] = None,
javaScriptEnabled: Optional[bool] = None,
bypassCSP: Optional[bool] = None,
userAgent: Optional[str] = None,
locale: Optional[str] = None,
timezoneId: Optional[str] = None,
geolocation: Optional[Geolocation] = None,
permissions: Optional[Sequence[str]] = None,
extraHTTPHeaders: Optional[Dict[str, str]] = None,
offline: Optional[bool] = None,
httpCredentials: Optional[HttpCredentials] = None,
deviceScaleFactor: Optional[float] = None,
isMobile: Optional[bool] = None,
hasTouch: Optional[bool] = None,
colorScheme: Optional[ColorScheme] = None,
reducedMotion: Optional[ReducedMotion] = None,
forcedColors: Optional[ForcedColors] = None,
acceptDownloads: Optional[bool] = None,
defaultBrowserType: Optional[str] = None,
proxy: Optional[ProxySettings] = None,
recordHarPath: Union[Path, str, None] = None,
recordHarOmitContent: Optional[bool] = None,
recordVideoDir: Union[Path, str, None] = None,
recordVideoSize: Optional[ViewportSize] = None,
storageState: Union[StorageState, str, Path, None] = None,
baseURL: Optional[str] = None,
strictSelectors: Optional[bool] = None,
serviceWorkers: Optional[ServiceWorkersPolicy] = None,
recordHarUrlFilter: Union[Pattern[str], str, None] = None,
recordHarMode: Optional[HarMode] = None,
recordHarContent: Optional[HarContentPolicy] = None,
) -> BrowserContext:
...
from playwright-python.
All parameters of any Playwright API have None
as a default. This is more an implementation detail which we internally use to decide if a user has passed a parameter over or not. Internally in our code we check if it was provided or not (!== null/undefined
and then use it / use our default).
None
means for all our methods that the default will be used / treated like nothing was specified.
We can maybe get rid of all the = None
everywhere.
from playwright-python.
Using None
that way is fine, but the parameter type hints should be either Union[SomeType, None]
, Optional[SomeType]
, or SomeType | None
(preferred, but may cause some issues in Python 3.9)
from playwright-python.
I am also okay with defaulting to None
, I just request the docstring state:
- The correct default of
None
- That
None
is equivalent toFalse
, within the implementation
So it's changing from:
Enable Chromium sandboxing. Defaults to
false
.
To:
Enable Chromium sandboxing. Defaults to
None
, which is equivalent toFalse
.
from playwright-python.
Related Issues (20)
- [Docs]: Update documentation on basic authentication with pytest HOT 1
- [Bug]: BrowserType.connect doesn't work with the Pytest plugin HOT 1
- [Ports]: Backport client side changes
- [Question]:When I use connect_over_cdp and the download request method is POST, expect_download cannot work,This is a common bug
- How to wait a new page loading? HOT 1
- [Question]:When I use connect_over_cdp and the download request method is POST, expect_download cannot work HOT 5
- 👾👾[Bug]: Can not login twitter by the cookies HOT 3
- modify the browser options
- [Docs]: How to modify firefoxPrefs with python / pytest.ini HOT 3
- [Bug]: Playwright Sync API Usage Issue: Error Encountered When Running Multiple Test Files HOT 2
- [Bug]: context_browse.route is broken for requests initiated by service worker HOT 1
- [Bug]: Future exception was never retrieved future: <Future finished exception=TargetClosedError('Target page, context or browser has been closed')> HOT 1
- TimeoutError on locator click
- [Bug]: Website reached from Docker behaves differently HOT 1
- PyInstaller can't package chromium driver on x86_64[Bug]: HOT 4
- [Bug]: Blackscreen browser headless=False CHROME HOT 1
- Python Playwright doesn't work in my computer HOT 2
- Why does executing pytest --tracing on in some code not produce the trace.zip file and also delete the existing test-results directory HOT 6
- [Bug]: `EventContextManager` does not conform to `AbstractContextManager` protocol
- [Feature]: Add extra logging for the PW
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright-python.