Skip to content

Is it possible to force the webdriver page to reconnect until an available connection is made? #2542

Answered by GladistonXD
GladistonXD asked this question in Q&A
Discussion options

You must be logged in to vote

I did it with 'dns.lookup' but I believe it can be improved, but it's functional

const dns = require('dns');

function sleep(timeMs) {
  return new Promise((resolve) => setTimeout(resolve, timeMs));
}

function isOffline() {
  return new Promise((resolve) => {
    dns.lookup('www.google.com', async (error) => (
      error ? resolve(true) : resolve(false)
    ));
  });
}

async function waitForOnlineStatus() {
  while (await isOffline()) {
    console.log('Offline');
    await sleep(2000);
  }
    console.log('Online')
    create({
        sessionId: 'Client',
        headless: true,
        multiDevice: true,
        qrTimeout: 0,
        authTimeout: 0,
        cacheEnabled: true,
     …

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by smashah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2541 on March 06, 2022 00:08.