question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Difference between --headless and not, emulating login

See original GitHub issue

I don’t think that this is directly a problem with chrome-remote-interface but I thought I would log it here just in case it is. In the following code, I’m emulating a login with amazon. The problem is that it works if I don’t start chrome headless but with remote debugging. If I simply add the --headless and take a screenshot, it says “enter valid email or mobile number.” The values show dumped to console in both instances and they are correct.

screenshot

try {
    await Network.enable();
    await Security.enable();
    await Security.setOverrideCertificateErrors({override: true});
    await Page.enable();
    await DOM.enable();
    await Network.setCacheDisabled({cacheDisabled: true});
    await Page.navigate({url: 'https://www.amazon.com/'});
    await Page.loadEventFired();
    result = await Runtime.evaluate({
        expression: 'document.getElementById("ap_email").value = "email@host.com"'
    });
    var result = await Runtime.evaluate({
        expression: 'document.getElementById("ap_password").value = "password"'
    });
    result = await Runtime.evaluate({
        expression: 'document.getElementById("ap_password").value'
    });
    console.log(result);
    result = await Runtime.evaluate({
        expression: 'document.getElementById("ap_email").value'
    });
    console.log(result);
    result = await Runtime.evaluate({
        expression: 'document.getElementsByName("signIn")[0].submit()'
    });
    await Page.loadEventFired();
    const {data} = await Page.captureScreenshot();
    fs.writeFileSync('screenshot.png', Buffer.from(data, 'base64'));
} catch (err) {
    console.error(err);
} finally {
    client.close();
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nospam2kcommented, Feb 7, 2018

Ok, I’ve set up an account and I have a reproducable script in full. How can I get you the credentials?

const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');
const fs = require('fs');

/**** Parameters ****/
const clientId = '';
const userName = '';
const password = '';
const headless = false;


let pageNum = 0;

chromeLauncher.launch({
	port: 9222,
	chromeFlags: [
		'--window-size=412,732',
		'--disable-gpu',
		(headless === true) ? '--headless' : ''
	]
}).then(async chrome => {
    try {
		var client = await CDP();
		const {DOM, Security, Network, Page, Runtime} = client;
		Security.certificateError(({eventId}) => {
			Security.handleCertificateError({
				eventId,
				action: 'continue'
			});
		});
        await Network.enable();
        await Security.enable();
        await Security.setOverrideCertificateErrors({override: true});
        await Page.enable();
        await DOM.enable();
        await Network.setCacheDisabled({cacheDisabled: true});
        await Page.navigate({url: 'https://www.amazon.com/ap/oa?client_id=' + clientId + '&scope=alexa%3Aall&scope_data=%7B%22alexa%3Aall%22%3A%7B%22productID%22%3A%22test_device%22%2C%22productInstanceAttributes%22%3A%7B%22deviceSerialNumber%22%3A%226507626777%22%7D%7D%7D&response_type=code&state=6022c10f-6cbc-50&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fauthresponse'});
        await Page.loadEventFired();
        await Runtime.evaluate({
            expression: 'document.getElementById("ap_email").value = "' + userName + '"'
        });
        await Runtime.evaluate({
            expression: 'document.getElementById("ap_password").value = "' + password + '"'
        });
        var result = await Runtime.evaluate({
            expression: 'document.getElementById("ap_password").value'
        });
        console.log(result);
        result = await Runtime.evaluate({
            expression: 'document.getElementById("ap_email").value'
        });
        console.log(result);
        result = await Runtime.evaluate({
            expression: 'document.getElementsByName("signIn")[0].submit()'
        });
        await Page.loadEventFired();
        const {data} = await Page.captureScreenshot();
        fs.writeFileSync('screenshot.png', Buffer.from(data, 'base64'));
		client.close();
		chrome.kill();
    } catch (err) {
        console.error(err);
    } finally {
        client.close();
		chrome.kill();
    }
});

Result screen shots: Full: screenshot-head Headless: screenshot-headless

0reactions
nospam2kcommented, Feb 8, 2018

Thanks, I’ll look into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is Headless Browser And Headless Browser Testing
Headless – Oh Yes, you read it right. Headless, means a Web Browser without User Interface. To elaborate, Headless Browsers are those which ......
Read more >
What is Headless Browser Testing and Why is it Important?
So, when it comes to Headless Browsers (Yep! You heard it right, it is called “headless”), it means a browser without a user...
Read more >
python 3.x - google login working in without headless but not ...
im trying to login into my google account using python selenium with chromedriver, the code works but not in headless mode. in hm...
Read more >
How to Test on Headless Emulators and Simulators with Appium
Find out how you can use Appium to start Android emulators and iOS simulators in a "headless" mode.
Read more >
Getting Started with Headless Chrome - Chrome Developers
A headless browser is a great tool for automated testing and server environments where you don't need a visible UI shell.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found