Closed ImKumin closed 1 year ago
Hi, please attach full source code which leads to following error
Error: Unable to set correct viewport size.
at exports.setViewport
Or describe steps to reproduce.
The steps to reproduce is having 2 or more tabs opened before the viewport resize is called. These 2 or more tabs can be opened, for example, by adding extensions that open tabs on browser startup.
In the code below, you can see that I use 3 extensions. One of them opens a new tab when the context is launched, resulting in 2 tabs before the viewport resize.
static async generateContext(name, headless, newFingerprint) {
await this._generateFingerprint(name, newFingerprint);
let args = [
`--disable-extensions-except=${this.NOCAPTCHAAI_PATH},${this.SURFSHARK_PATH},${this.TAMPERMONKEY_PATH}`,
`--load-extension=${this.NOCAPTCHAAI_PATH}`,
`--load-extension=${this.SURFSHARK_PATH}`,
`--load-extension=${this.TAMPERMONKEY_PATH}`
];
if (headless)
args.push(`--headless=new`);
return await plugin.launchPersistentContext(`instances-data/instance-${name}`, {
headless: headless,
args: args,
crx: [this.NOCAPTCHAAI_PATH, this.SURFSHARK_PATH, this.TAMPERMONKEY_PATH],
name: name
});
}
Here is the full code: ContextGenerator.zip
Was able to reproduce with following code, @CheshireCaat please check after https://gitlab.com/bablosoft/bas/-/issues/372
const {plugin} = require('playwright-with-fingerprints');
const {readFile, writeFile} = require('fs/promises');
const fs = require("fs");
class ChromiumContextGenerator {
static SURFSHARK_PATH = '--- REPLACE WITH PATH TO ailoabdmgclmfmhdagmlohpjlbpffblp ---';
static async generateContext(name, headless, newFingerprint) {
await this._generateFingerprint(name, newFingerprint);
let args = [
`--disable-extensions-except=${this.SURFSHARK_PATH}`,
`--load-extension=${this.SURFSHARK_PATH}`,
];
if (headless)
args.push(`--headless=new`);
return await plugin.launchPersistentContext(`instances-data/instance-${name}`, {
headless: headless,
browserContextOptions: {
cpuThrottlingRate: 0.9,
memory: 8
},
args: args,
crx: [this.SURFSHARK_PATH],
name: name
});
}
static async _generateFingerprint(name, newFingerprint) {
let fileName = `fingerprints/instance-${name}`;
let fileExists = newFingerprint ? false : fs.existsSync(fileName);
const fingerprint = fileExists ? await readFile(fileName, 'utf8') : await plugin.fetch('', {
tags: ['Microsoft Windows', 'Chrome'],
});
if (!fileExists)
await writeFile(fileName, fingerprint);
plugin.useFingerprint(fingerprint);
}
}
ChromiumContextGenerator.generateContext("test", false, false)
This should be fixed for now
Hello, I've noticed that if the browser has 2 or more tabs open (tabs opened from extensions), it fails to set the viewport size.
Also, I don't really need the fingerprint to change the viewport; Is there a way to leave its size unchanged?
I don't think it is needed, but in any case, here is my code: