Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] page.waitForSelector fails when called during a redirect #4002

Closed
celeryclub opened this issue Sep 29, 2020 · 8 comments
Closed

[BUG] page.waitForSelector fails when called during a redirect #4002

celeryclub opened this issue Sep 29, 2020 · 8 comments
Assignees

Comments

@celeryclub
Copy link
Contributor

celeryclub commented Sep 29, 2020

Context:
System:
OS: macOS 10.15.7
Memory: 226.13 MB / 32.00 GB
Binaries:
Node: 12.18.3 - /var/folders/sn/fccqtk995ll0h2b7wtp1z_z80000gr/T/fnm-shell-5071240/bin/node
npm: 6.14.8 - /var/folders/sn/fccqtk995ll0h2b7wtp1z_z80000gr/T/fnm-shell-5071240/bin/npm
Languages:
Bash: 3.2.57 - /bin/bash

Describe the bug

Hi team. I'm seeing an issue with waitForSelector throwing an error in some cases. When I call it during a series of server redirects, it's throwing. However, if I use waitForTimeout to let the redirects finish, and then call waitForSelector, everything is fine.

// fill out a form and click "submit"
// this process redirects several times through various hostnames
await page.waitForSelector('.logo');

When I run this, I see this error:

UnhandledPromiseRejectionWarning: page.waitForSelector: Evaluation failed: TypeError: injected.pollRaf is not a function
    at eval (__playwright_evaluation_script__217:3:25)
    at UtilityScript.callFunction (__playwright_evaluation_script__206:305:24)
    at UtilityScript.<anonymous> (__playwright_evaluation_script__227:1:44)

Or sometimes this error:

UnhandledPromiseRejectionWarning: page.waitForSelector: Protocol error (Runtime.callFunctionOn): Could not find object with given id

I've tried creating a minimal repro of this issue, but I'm struggling to get it to happen outside of my staging environment. Any suggestions for a potential way to repro this would be much appreciated.

@dgozman
Copy link
Contributor

dgozman commented Sep 30, 2020

This is very interesting. TypeError: injected.pollRaf is not a function is unexpected, because pollRaf is always a function.

My immediate guess would be that InjectedScript is corrupted on some redirect hosts, because they override some builtins like Promise. However, your example selector is '.logo' which should always use the utility context and avoid the overridden builtins problem.

Could it be that in the actual scenario you use a custom selector engine, or different selector, or maybe page.$eval or similar?

@celeryclub
Copy link
Contributor Author

Thanks for the input @dgozman. This is a pretty simple case apart from the redirects. I do actually have a repro to share, it's just not a minimal one. But at least you can see what code I'm using. This repro requires the uuid package to be installed locally.

const { chromium } = require('playwright-chromium');
const { v1: uuid } = require('uuid');

const AdobeSusi = {
  emailField: '#Signup-EmailField',
  firstNameField: '#Signup-FirstNameField',
  lastNameField: '#Signup-LastNameField',
  passwordField: '#Signup-PasswordField',
  dayOfBirthField: '.Signup-DateOfBirthChooser__day input',
  yearOfBirthField: '.Signup-DateOfBirthChooser__year input',
  createAccountButton: '.spectrum-Button-label >> text="Create account"',
  passwordStrengthIndicator: '.PasswordStrength',
};

function generateUserData() {
  const uniqueID = uuid().replace('-', '');

  return {
    firstName: `first${uniqueID}`,
    lastName: `last${uniqueID}`,
    dob: '1990-01-01',
    email: `automation-${uniqueID}@gmail.com`,
    countryCode: 'US',
    username: `automation-${uniqueID}@gmail.com`,
    password: 'P@ssword',
    companyValue: 'Loud Talkers',
    titleValue: 'Automation Tester',
    cityValue: 'Mobile',
    location: 'Mobile, AL, USA',
  };
}

async function signUpThroughSusiUi(page) {
  const userData = generateUserData();

  await page.type(AdobeSusi.emailField, userData.email);
  await page.type(AdobeSusi.firstNameField, 'Automated');
  await page.type(AdobeSusi.lastNameField, 'Tester');
  await page.type(AdobeSusi.passwordField, userData.password);
  await page.type(AdobeSusi.dayOfBirthField, '1');
  await page.type(AdobeSusi.yearOfBirthField, '1990');
  await page.waitForSelector(AdobeSusi.passwordStrengthIndicator, { state: 'hidden' });
  await page.click(AdobeSusi.createAccountButton);
}

(async () => {
  const browser = await chromium.launch({
    headless: false,
  });

  const page = await browser.newPage();

  await page.goto('https://www.behance.net', { waitUntil: 'domcontentloaded' });
  await page.waitForTimeout(2000);
  await page.click('.js-adobeid-signup');
  await signUpThroughSusiUi(page);
  // await page.waitForTimeout(5000);
  // ^ If I add this line back in it works, most likely because
  // all the redirects have finished before waitForSelector is called
  await page.waitForSelector('.rf-logo');

  await browser.close();
})();

@dgozman
Copy link
Contributor

dgozman commented Oct 2, 2020

@celeryclub Thanks for the script, I am able to repro! Sometimes it fails with timeout trying to navigate, but other times I can see the waitForSelector issue 😄 Will look into this.

@celeryclub
Copy link
Contributor Author

Thanks so much @dgozman!

@dgozman
Copy link
Contributor

dgozman commented Oct 5, 2020

When running against the ToT Playwright, I get the Could not find object with given id error in response to Runtime.callFunctionOn.

This seems to be caused by remote object ids clashing between different processes, e.g. {\"injectedScriptId\":4,\"id\":1}. This could also explain the pollRaf is not a function error, in the case objectId is valid but points to a different type of object (not InjectedScript). From what I can see, WebKit might suffer from the same problem when swapping processes on navigation.

@dgozman
Copy link
Contributor

dgozman commented Nov 2, 2020

I think this should be fixed with the latest Chromium roll. Let me close this optimistically 😄 Please comment/reopen if the issue persists.

@pixelastic
Copy link

Hello, we're having the same issue with playwright-electron v0.5.0. Our tests randomly fail with injected.pollRaf is not a function as well.

Note that they work correctly when ran with a visible electron window, but fail when ran through xvfb-run (like we do on our CI)

(I'm pinging you @dgozman because I'm not sure commenting on a closed issue will be trigger a notification)

@dgozman
Copy link
Contributor

dgozman commented Feb 23, 2021

@pixelastic This should be fixed with the next version of Electron itself, once the fix from Chromium is rolled in. So, if you plan to upgrade your Electron to the next version, things should work. I believe that Electron 12 that is based on Chromium M89 will have the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants