-
Notifications
You must be signed in to change notification settings - Fork 2
Add Playground page for Lightpanda Cloud
#80
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ee76f0
Add Playground page for Lightpanda Cloud
cdebled eb86de6
Point to the playground from the cloud getting started page
cdebled 87d3db7
Note the playground connection variable on the Puppeteer and Playwrig…
cdebled 32364e4
Note that playground runs count toward plan limits
cdebled 8b43cea
Adapt the playground cross-references to the reworked cloud pages
cdebled 2a0dd01
Trim the playground page: drop the UI walkthrough and duplicated expl…
cdebled b279cac
Apply review feedback on the playground and limits pages
cdebled File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| --- | ||
| title: Playground | ||
| description: Write and run browser automation scripts from the Lightpanda Cloud console, with Puppeteer and Playwright preinstalled and no local setup. | ||
| --- | ||
|
|
||
| import { Tabs, Callout } from 'nextra/components' | ||
|
|
||
| # Playground | ||
|
|
||
| The playground is a [code editor](https://console.lightpanda.io/playground/scripts) in the console that runs your automation scripts on Lightpanda Cloud. | ||
|
|
||
| ## Write and run a script | ||
|
|
||
| Your script reaches the browser through `CDP_WS_URL`, an environment variable the playground sets for you: | ||
|
|
||
| <Tabs items={['Playwright', 'Puppeteer']}> | ||
| <Tabs.Tab> | ||
| ```js copy | ||
| import { chromium } from 'playwright-core'; | ||
|
|
||
| // Connect Playwright's chromium driver to the browser. | ||
| const browser = await chromium.connectOverCDP(process.env.CDP_WS_URL); | ||
|
|
||
| const context = await browser.newContext({}); | ||
| const page = await context.newPage(); | ||
|
|
||
| await page.goto('https://wikipedia.com/'); | ||
|
|
||
| const title = await page.locator('h1').textContent(); | ||
| console.log(title); | ||
|
|
||
| await page.close(); | ||
| await context.close(); | ||
| await browser.close(); | ||
| ``` | ||
| </Tabs.Tab> | ||
| <Tabs.Tab> | ||
| ```js copy | ||
| import puppeteer from 'puppeteer-core'; | ||
|
|
||
| // Connect Puppeteer to the browser. | ||
| const browser = await puppeteer.connect({ | ||
| browserWSEndpoint: process.env.CDP_WS_URL, | ||
| }); | ||
|
|
||
| const context = await browser.createBrowserContext(); | ||
| const page = await context.newPage(); | ||
|
|
||
| await page.goto('https://wikipedia.com/'); | ||
|
|
||
| const title = await page.$eval('h1', el => el.textContent); | ||
| console.log(title); | ||
|
|
||
| await page.close(); | ||
| await context.close(); | ||
| await browser.disconnect(); | ||
| ``` | ||
| </Tabs.Tab> | ||
| </Tabs> | ||
|
|
||
| ## What CDP_WS_URL contains | ||
|
|
||
| You do not need to hard-code a token in your script. `CDP_WS_URL` holds the WebSocket address your client uses to reach the browser over the [Chrome DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) (CDP), assembled from the choices in the Default variables panel: | ||
|
|
||
| | Default variable | Values | What it controls | | ||
| | --- | --- | --- | | ||
| | Region | `euwest`, `uswest` | Which region serves the browser | | ||
| | Token | one of your active tokens | Which token the run authenticates with | | ||
| | Browser | `lightpanda`, `chrome` | Which browser runs. Chrome is for debugging, not production traffic | | ||
| | Proxy | one of your proxies, or none | The outbound IP the browser uses | | ||
|
|
||
| Pass `process.env.CDP_WS_URL` to whichever client you use. | ||
|
|
||
| <Callout type="info"> | ||
| `console.log(process.env.CDP_WS_URL)` prints `***`, not the URL. The URL carries an access token created for the run, and run output is stored in the console, so the playground masks the URL wherever it appears in output. | ||
| </Callout> | ||
|
|
||
| ## What the runtime provides | ||
|
|
||
| Scripts run in an isolated container. Both CDP clients are preinstalled at fixed versions, so there is no install step: | ||
|
|
||
| | Package | Version | | ||
| | --- | --- | | ||
| | `playwright-core` | 1.50.0 | | ||
| | `puppeteer-core` | 24.0.0 | | ||
|
|
||
| The rest of the environment is fixed too: | ||
|
|
||
| - **Language.** JavaScript and TypeScript both run through [tsx](https://tsx.is/), so `import` syntax and top-level `await` work in either without configuration. | ||
| - **Packages.** You cannot install anything beyond the two clients above. | ||
| - **Filesystem.** Read-only, apart from a writable `/tmp`. | ||
|
|
||
| Every run is capped: | ||
|
|
||
| | Limit | Value | | ||
| | --- | --- | | ||
| | Run time | 5 minutes | | ||
| | Memory | 256 MB | | ||
| | CPU | 1 core | | ||
| | Output captured | 256 KB | | ||
| | Processes | 64 | | ||
|
|
||
| A run that reaches 5 minutes stops and reports `timeout running program`. Output beyond 256 KB is dropped, and the run is flagged as truncated. | ||
|
|
||
| These caps apply to the script process. The browser session driven by the script also counts toward your [plan limits](/run-on-lightpanda-cloud/limits-and-billing). | ||
|
|
||
| The [Runs page](https://console.lightpanda.io/playground/script-runs) shows your run history and output for the past 30 days. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.