I’m running into a weird issue where my automation script works perfectly with Chrome but gets stuck when using Firefox. I have a Java application that calls a Node.js script to do some web scraping.
Java Code
Here’s my Java method that runs the Node script:
public void runNodeScript(){
try{
System.out.println(scriptCommand);
final long begin = System.currentTimeMillis();
final Process proc = Runtime.getRuntime().exec(scriptCommand);
System.out.println("WAITING FOR SCRIPT TO COMPLETE");
final Stream<String> output = new BufferedReader(new InputStreamReader(proc.getInputStream())).lines().peek(System.out::println);
System.out.println("Phase--->A");
final List<String> results = output.collect(Collectors.toList());
System.out.println("Phase--->B");
final long finish = System.currentTimeMillis();
if(results.isEmpty()){
System.out.println("no output received in: "+(finish-begin)+" ms");
} else {
System.out.println("received lines: " + results.size()+" in: "+(finish-begin)+" ms");
results.forEach(System.out::println);
}
} catch(final Exception ex){
ex.printStackTrace();
}
}
The script path looks like:
private final String scriptCommand = "node C:\\Users\\myuser\\Desktop\\FirefoxTest.js";
Working Chrome Version
This Node.js script works great with Chrome:
const { chromium } = require('playwright-extra')
const stealthPlugin = require('puppeteer-extra-plugin-stealth')()
chromium.use(stealthPlugin)
chromium.launch({ headless: false }).then(async browserInstance => {
const newPage = await browserInstance.newPage()
console.log('Starting stealth test...')
await newPage.goto('https://bot.sannysoft.com', { waitUntil: 'networkidle' })
await newPage.screenshot({ path: 'result.png', fullPage: true })
console.log('Test completed successfully')
await browserInstance.close()
})
Problematic Firefox Version
But when I switch to Firefox, it never completes:
const { firefox } = require('playwright-extra')
const stealthPlugin = require('puppeteer-extra-plugin-stealth')()
firefox.use(stealthPlugin)
firefox.launch({ headless: false }).then(async browserInstance => {
const newPage = await browserInstance.newPage()
console.log('Starting stealth test...')
await newPage.goto('https://bot.sannysoft.com', { waitUntil: 'networkidle' })
await newPage.screenshot({ path: 'result.png', fullPage: true })
console.log('Test completed successfully')
await browserInstance.close()
})
The Firefox version launches two browser windows instead of one and gets stuck at the page navigation step. The page loads but the script never moves past the goto command even though the network appears idle. When I run this same Firefox script directly from command line it works fine, but not when called from Java.
Anyone know why Firefox behaves differently here or how to fix this hanging issue?