I have developed a form filling application using puppeteer with nodejs. my code normally only works in pure form. but when I combine it with electron the css and js files are not loaded on the site. All I did was get the data to be entered in the form from the electron html page. but i ran into such a problem in a way that i don’t understand. My research says it’s a cors problem, but I couldn’t find a solution.
I leave my code below.
const puppeteer = require('puppeteer-extra')
const request = require('request');
const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')
const useProxy = require('puppeteer-page-proxy');
var settings = {
country: "Turkey",
city: "Istanbul",
namesurname: "name surname",
username: "testusername",
metin: "bla bla bla",
};
const sendForm = async (numOfPages, formProxy) => {
const browser = await puppeteer.launch({
headless: false,
args: [
'--disable-web-security',
'--disable-features=IsolateOrigins',
'--disable-site-isolation-trials'
]
});
for (let i = 1; i <= numOfPages; i++) {
console.log(i + ". işlem başladı");
try {
const page = await browser.newPage();
await useProxy(page, 'http://192.168.1.1:8080'); //random proxy
const data = await useProxy.lookup(page);
if (!data) throw console.error('No data');
await page.goto('https:help.instagram.com/contact/1784471218363829', { waitUntil: 'networkidle2' });
// click actions
console.log(i + ". İşlem Tamamlandı")
} catch (error) {
console.error('Beklenmedik bir hata oluştu tekrar deneniyor.');
console.error(error);
i--;
continue;
}
await new Promise(resolve => setTimeout(resolve, 1000));
}
await browser.close();
console.log("Tüm işlemler tamamlandı");
};
This code block works when not in electron.
Electron main.js
function createWindow() {
win = new BrowserWindow({
autoHideMenuBar: true,
frame: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
}
});
win.loadURL(`file://${__dirname}/src/login.html`);
initIPCMain();
// Open the DevTools.
win.webContents.openDevTools();
win.on("closed", () => {
win = null;
});
win.webContents.on('did-finish-load', () => {
win.webContents.insertCSS('body::-webkit-scrollbar { display: none; }')
console.log('Tüm kaynaklar yüklendi.');
});
};
There is one thing I noticed, when I don’t use a proxy, it comes correctly and I don’t have a problem.
Sorry for my bad english.
my research says it’s a cors error. I tried some solutions I found on the internet but it didn’t work.
Solutions I tried;
Electron
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webSecurity: false, // cors error fix
}
Puppeteer
args: [
'--disable-web-security',
'--disable-features=IsolateOrigins',
'--disable-site-isolation-trials'
]
I tried these but it didn’t work