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.

JS disabled in Puppeteer even after `page.setJavaScriptEnabled(true);`

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.18.1-next.1562564221866
  • Platform / OS version: Mac OSX Mojave 10.14.5
  • URLs (if applicable): https://www.youtube.com/
  • Node.js version: 11.13.0

What steps will reproduce the problem?

const puppeteer = require('puppeteer');

(async() => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    //Allow JS.
    await page.setJavaScriptEnabled(true);

    //Go to YouTube homepage.
    await page.goto('https://www.youtube.com/', {
        waituntil: 'domcontentloaded',
    });

    //Click the sign in button at the top.
    await page.click('#buttons #text');

    //Fill out the username and click 'Next' (submit form).
    await page.waitForSelector('input[type="email"]');
    await page.type('input[type="email"]', USERNAME)
    await page.$eval('form', form => form.submit());

    //Fill out the password click 'SignIn' (submit form).
    await page.waitForSelector('input[type="password"]');
    await page.type('input[type="password"]', PASSWORD);
    await page.$eval('form', form => form.submit());

    //Take a screenshot of the page.
    await await page.screenshot({
        path: `test.png`,
        fullPage: true
    });

    await browser.close()
})();

I have also tried launching browser with args: ['--no-sandbox', '--disable-setuid-sandbox'] with no success.

Here is what my code does:

  1. Goto https://www.youtube.com/.
  2. Click SignIn (top right).
  3. Fill in username and click Next.
  4. Fill in password and click Submit.

What is the expected result? A redirection back to YouTube homepage.

What happens instead? I get an error saying:

Couldn't sign you in 
The browser you are using doesn't support JavaScript, or has JavaScript turned off.

test

I seem to have no issues when doing the listed steps manually on my Browser.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rahtrcommented, Aug 27, 2019

Any updates on this. I tried all the possible solutions as mentioned by the author of this post but can’t make it work👍

Setup Test Environment.
 FAIL  __tests__/test1.js
  / (Home Page)
    ✕ should load without error (1158ms)

  ● / (Home Page) › should load without error

    expect(received).toContain(expected) // indexOf

    Expected substring: " Services"
    Received string:    "·····
          You need to enable JavaScript to run this app.·····

Here is my code:

const timeout = 5000
describe(
  '/ (Home Page)',
  () => {
    let page
    beforeAll(async () => {
      page = await global.__BROWSER__.newPage()
      await page.setJavaScriptEnabled(true)
      await page.waitFor(1000);
    }, timeout)

    afterAll(async () => {
      await page.close()
    })

    it('should load without error', async () => {
      await page.goto('http://0.0.0.0:3000/#/')
      let text = await page.evaluate(() => document.body.textContent)
      expect(text).toContain(' Services')
    })
  },
  timeout
)

0reactions
Barresidercommented, Nov 24, 2020

To change this behavior for puppeteer you have to set the user-agent in your args-options when launching. For example:

args: [
        "--no-sandbox",
        "--disable-setuid-sandbox",
        '--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36"',
      ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I disable javascript in puppeteer? - Stack Overflow
Try the following: page.setJavaScriptEnabled(false). Set this before navigating to the website. More information to read on this you can ...
Read more >
Puppeteer documentation - DevDocs
Returns a list of devices to be used with page.emulate(options) . Actual list of devices can be found in src/common/DeviceDescriptors.ts . const puppeteer...
Read more >
puppeteer.Page.setJavaScriptEnabled JavaScript and Node ...
Determines whether JavaScript is enabled on the page. Most used puppeteer functions. launch. The method launches a browser instance with given arguments. The ......
Read more >
Avoiding Puppeteer Antipatterns - SerpApi
When possible, consider disabling JS with page.setJavaScriptEnabled(false) , stopping the browser with page.evaluate(() => window.stop()) or ...
Read more >
Troubleshooting - Puppeteer
Chrome headless doesn't launch on Windows​ ... Some chrome policies might enforce running Chrome/Chromium with certain extensions. Puppeteer passes --disable- ...
Read more >

github_iconTop Related Medium Post

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