# Playwright

#### 什麼是Playwright？

[**Playwright**](https://playwright.dev/)由 Microsoft 構建，是一個 Node.js 庫，透過單一 API，可以自動化在 Chromium、Firefox 和 WebKit 上運行的網站和 Web 應用程式。編寫 JavaScript 程式碼的開發人員可以使用這些 API 來建立新的瀏覽器頁面、導航到 URL，然後與頁面上的元素互動。此外，由於 Microsoft Edge 建置在開源 Chromium Web 平台上，Playwright 還可以自動化 Microsoft Edge。

<figure><img src="/files/TL3PEydfYLRRbRwouOj7" alt=""><figcaption></figcaption></figure>

下面為您介紹如何將Thordata與Playwright集成。

{% stepper %}
{% step %}

### 安裝Playwright

首先使用 npm、yarn 或 pnpm 安裝 Playwright。或者，您也可以使用 VS Code 擴充功能開始並執行測試。

[**點擊此處**](https://playwright.dev/docs/intro)查看詳細安裝教程
{% endstep %}

{% step %}

### 在Playwright中填入代理值

**服務器:** `t.pr.thordata.net:9999`

**代理賬戶:** `td-customer-USERNAME`

**代理密碼:** `PASSWORD`
{% endstep %}
{% endstepper %}

**代碼示例：**

```
const playwright = require('playwright');
(async () => {
    for (const browserType of ['chromium', 'firefox', 'webkit']) {
        const browser = await playwright[browserType].launch({
            headless: false,
            proxy: {
                server: 'http://t.pr.thordata.net:9999',
                username: 'td-customer-USERNAME',
                password: 'PASSWORD'
            },
        });
        const context = await browser.newContext();
        const page = await context.newPage();
        await page.goto('https://ipinfo.thordata.com');
        await page.screenshot({ path: `${browserType}.png` });
        await browser.close();
    }
})();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.thordata.com/doc/zh-hk/dai-li/ji-cheng-jiao-cheng/zhu-zhai-dai-li-ji-cheng/playwright.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
