Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

More control over tab.run() / tab.wait() / tab.waitForNewPage behaviour #31

Open

Description

Example of current behaviour:

// Current situation:
await tab.wait(async () => {
    await wait.documentComplete()
              .selectorAll('.gallery > img')
              .count(10, Infinity)
              .isDisplayed()
    link = await wait.selector('a[href].nextPage')
})

// this will error because the script is aborted by the page navigation
await tab.run(async () => {
    await interact.click(link)
});

// This is the correct version:
await tab.waitForNewPage(async () => {
    await interact.click(link)
});

We could make this a lot less verbose by giving the scripter more control over the behaviour of these functions, from within the content script. For example:

await tab.wait(async () => {
    await wait.documentComplete()
              .selectorAll('.gallery > img')
              .count(10, Infinity)
              .isDisplayed()
    const link = await wait.selector('a[href].nextPage')

    // triggers the same behaviour as tab.waitForNewPage()
    await this.expectNewPage() 
    await interact.click(link)
})

// full usage example
await tab.wait(async () => {
    // .result(): sets the result of the outer promise. Also, the .wait() callback body 
    // will not repeat for the next page. However the outer promise will still wait
   // until the callback body completes, or the page navigates away
    await this.result(123)
    // .reject(): same as result() but rejects instead of resolve 
              .error(Error('foo'))
    // triggers the same behaviour as tab.waitForNewPage() and it also 
    // implies .result(undefined) if no result had been set
              .expectNewPage()

    // the `runMetadata` global can then be renamed to `this.meta`
    console.log(new Date(this.meta.waitBeginTime));
})

Activity

  1. ghost changed the title [-]Rename tab.wait() to tab.repeat()[/-] [+]More control over tab.run() / tab.wait() / tab.waitForNewPage behaviour[/+] on Jul 10, 2018
  2. ghost added this to the Beta Launch milestone on Jul 10, 2018
  3. ghost removed this from the Beta Launch milestone on Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions