最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I use a persistent context with extensions when connecting remotely via Aerokube Moon in Playwright? - Stac

programmeradmin3浏览0评论

I am working with Playwright and setting up tests using Aerokube Moon. In my configuration, I connect remotely to the browser using chromium.connect, which allows me to pass additional parameters through the URL. Here’s an example of my code:

`if (moonConfig.enableMoon) { console.log("Starting test via Aerokube - Moon");

const wsUrl = new URL(moonConfig.remoteUrl);
// For each key in capabilities:
// If the value is an array, add each element as a separate parameter,
// otherwise set the parameter directly.
for (const [key, value] of Object.entries(moonConfig.capabilities)) {
    if (Array.isArray(value)) {
        for (const item of value) {
            wsUrl.searchParams.append(key, item);
        }
    } else {
        wsUrl.searchParams.set(key, value);
    }
}

this.browser = await chromium.connect({ wsEndpoint: wsUrl.toString() });
this.context = await this.browser.newContext({ viewport: { width: 1920, height: 1080 } });
this.page = await this.context.newPage();

}`

The issue is that using newContext() creates an incognito context where I cannot use extensions. I need a persistent context (to load extensions), which is typically created using the launchPersistentContext method.

However, if I try to use launchPersistentContext, I get type errors because this method is not supported when using remote connections via chromium.connect.

My question: Is there any workaround to use a persistent context (with extension support) when connecting remotely via Aerokube Moon? Or do I need to separate the launch logic based on the environment (i.e., local for persistent context and remote for incognito context)?

Any advice or alternative approaches would be greatly appreciated.

Thank you!

I attempted to use launchPersistentContext when connecting via Aerokube Moon, expecting to get a persistent context with extension support. Instead, I got type errors since persistent contexts aren’t supported with remote connections; chromium.connect only allows creating incognito contexts via newContext()

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论