MCPcopy
hub / github.com/marimo-team/marimo / _init_browser

Method _init_browser

marimo/_code_mode/screenshot.py:121–168  ·  view source on GitHub ↗

Start Playwright + Chromium and navigate to the kiosk page. On failure, any partially-created resources are cleaned up before re-raising.

(self)

Source from the content-addressed store, hash-verified

119 await self._init_browser()
120
121 async def _init_browser(self) -> None:
122 """Start Playwright + Chromium and navigate to the kiosk page.
123
124 On failure, any partially-created resources are cleaned up
125 before re-raising.
126 """
127 async_playwright = _require_playwright()
128
129 LOGGER.debug("Screenshot session: launching browser")
130 pw = await async_playwright().start()
131 browser: Any = None
132 page: Any = None
133 try:
134 try:
135 browser = await pw.chromium.launch()
136 except Exception as err:
137 msg = str(err).lower()
138 if (
139 "executable doesn't exist" in msg
140 or "looks like playwright" in msg
141 ):
142 _raise_browser_missing(err)
143 raise
144
145 context = await browser.new_context(
146 viewport={
147 "width": _VIEWPORT_WIDTH,
148 "height": _VIEWPORT_HEIGHT,
149 },
150 device_scale_factor=_DEVICE_SCALE_FACTOR,
151 )
152 page = await context.new_page()
153 await page.emulate_media(reduced_motion="reduce")
154
155 # Commit only after full success.
156 self._playwright = pw
157 self._browser = browser
158 self._page = page
159 await self._navigate(initial=True)
160 LOGGER.debug("Screenshot session: ready")
161 except BaseException:
162 # Clean up partially-created resources.
163 if browser is not None:
164 with _suppress():
165 await browser.close()
166 with _suppress():
167 await pw.stop()
168 raise
169
170 async def _navigate(self, *, initial: bool) -> None:
171 """Navigate (initial=True) or reload (initial=False) the kiosk page."""

Callers 1

_ensure_readyMethod · 0.95

Calls 11

_navigateMethod · 0.95
_require_playwrightFunction · 0.85
_raise_browser_missingFunction · 0.85
_suppressFunction · 0.85
launchMethod · 0.80
new_contextMethod · 0.80
new_pageMethod · 0.80
closeMethod · 0.65
debugMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected