# Playwright (Firefox) with Node.js

import { Tabs, TabsContent, TabsList, TabsTrigger } from "zudoku/ui/Tabs"

{/* vale off */}
{/* THIS FILE WAS AUTOGENERATED FROM THE PUBLIC EXAMPLE REPOSITORY. DO NOT EDIT THIS FILE DIRECTLY. */}


[Playwright](https://playwright.dev/) is a framework for web testing and Automation.

To run this example, follow these steps:

1. Install the [unikraft CLI](/cli).
   You need a [BuildKit](https://github.com/moby/buildkit) builder. The easiest way to get one is via [Docker](https://docs.docker.com/engine/install/).
   Alternatively, you can also directly set up and use BuildKit, see the [quick start](https://github.com/moby/buildkit#quick-start).

2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/node-playwright-firefox/` directory:

   ```bash
   git clone https://github.com/unikraft-cloud/examples
   cd examples/node-playwright-firefox/
   ```

Make sure to log into Unikraft Cloud and pick a [metro](/platform/metros) close to you.
This guide uses `fra` (Frankfurt, 🇩🇪):

```bash
unikraft login
```

When done, invoke the following command to deploy this app on Unikraft Cloud:

```bash
unikraft build . --output <my-org>/node-playwright-firefox:latest
unikraft run --metro fra \
  -m 4G \
  -p 443:8080/tls+http \
  --scale-to-zero policy=idle,cooldown-time=1000,stateful=true \
  --image <my-org>/node-playwright-firefox:latest
```

The output shows the instance address and other details:

```ansi
[1mmetro[22m:        fra
[1mname[22m:         node-playwright-firefox-q3m9k
[1muuid[22m:         d4e5f6a7-b8c9-0d1e-2f3a-d4e5f6a7b8c9
[1mstate[22m:        [38;2;144;161;185mstarting[0m
[1mimage[22m:        <my-org>/node-playwright-firefox
[1mresources[22m:
[3m  memory[23m:     4096MiB
[3m  vcpus[23m:      1
[1mservice[22m:
[3m  uuid[23m:       e5f6a7b8-c9d0-1e2f-3a4b-e5f6a7b8c9d0
[3m  name[23m:       bright-lake-dh6xp2sq
[3m  domains[23m:
[3m  - fqdn[23m:     bright-lake-dh6xp2sq.fra.unikraft.app
[1mnetworks[22m:
[3m- uuid[23m:       f6a7b8c9-d0e1-2f3a-4b5c-f6a7b8c9d0e1
[3m  private-ip[23m: 10.0.5.3
[3m  mac[23m:        12:b0:9f:6b:de:c8
[1mtimestamps[22m:
[3m  created[23m:    just now
```

In this case, the instance name is `node-playwright-firefox-q3m9k` and the address is `https://bright-lake-dh6xp2sq.fra.unikraft.app`.
They're different for each run.

The command will deploy the files in the current directory.
It results in the creation of a remote web-based service for creating PNG screenshots of remote pages.

Use the `?page=<REMOTE_URL>` to point the service to the remote page to screenshot.
Query the service using commands such as:

```console
curl "https://<NAME>.<METRO>.unikraft.app/?page=https://google.com" -o ss-google.png
curl "https://<NAME>.<METRO>.unikraft.app/?page=https://bing.com" -o ss-bing.png
```

You can list information about the instance by running:

```bash
unikraft instances list
```

```ansi
[1mMETRO[22m  [1mNAME[22m                           [1mSTATE[22m    [1mIMAGE[22m                             [1mARGS[22m  [1mMEMORY[22m   [1mVCPUS[22m  [1mFQDN[22m                                   [1mCREATED[22m
fra    node-playwright-firefox-q3m9k  [38;2;0;188;125mrunning[0m  <my-org>/node-playwright-firefox        4096MiB  1      bright-lake-dh6xp2sq.fra.unikraft.app  2 minutes ago
```

When done, you can remove the instance:

```bash
unikraft instances delete <instance-name>
```

## Learn more

- [Playwright's Documentation](https://playwright.dev/docs/intro)
- [Unikraft Cloud's Documentation](https://unikraft.cloud/docs/)
- [Building `Dockerfile` Images with `Buildkit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)


Use the `--help` option for detailed information on using Unikraft Cloud:

```bash
unikraft --help
```

Or visit the [CLI Reference](/cli/unikraft).
{/* vale on */}
