# 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/proxies/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.
