async function waitForFunction(session, fn, deps) {
  let iterations = 0;
  while (true) {
    try {
      return await evaluateInSession(session, fn, deps);
    } catch (err) {
      // Random transient errors are common when first booting up.
      // Only surface errors if this fails 10 times in a row (~5s)
      if (iterations > 10) {
        console.error(`Error waiting for function (#${iterations}):`);
        console.error(err);
        console.error('Retrying...');
      }
      await new Promise(r => setTimeout(r, 500));
    } finally {
      ++iterations;
    }
  }
}
Similar to {@link evaluateInSession}, this is a light re-implementation of Puppeteer's `page.waitForFunction`.

@template R [unknown]
@param {puppeteer.CDPSession} session
@param {() => (R|Promise<R>)} fn
@param {Function[]} [deps]
@return {Promise<R>}