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

Simulating user gesture during script evaluation (script.evaluate, script.callFunction) #359

Closed
OrKoN opened this issue Jan 30, 2023 · 3 comments · Fixed by #496
Closed
Labels
enhancement New feature or request needs-discussion Issues to be discussed by the working group script Script module

Comments

@OrKoN
Copy link
Contributor

OrKoN commented Jan 30, 2023

Puppeteer provides the ability to evaluate JavaScript while emulating the user action. In the following test, the expected result is true although there was no explicit user action to trigger the execution of the script:

   it('should simulate a user gesture', async () => {
      const {page} = getTestState();

      const result = await page.evaluate(() => {
        document.body.appendChild(document.createTextNode('test'));
        document.execCommand('selectAll');
        return document.execCommand('copy');
      });
      expect(result).toBe(true);
    });

it looks like WebDriver BiDi does not offer this capability yet but it probably should be added. In CDP, the userGesture flag is responsible for this feature: https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-evaluate

@whimboo whimboo added enhancement New feature or request script Script module needs-discussion Issues to be discussed by the working group labels Jan 30, 2023
@whimboo whimboo changed the title Simulating user gesture during evaluate Simulating user gesture during script evaluation (script.evaluate, script.callFunction) Jan 30, 2023
@jgraham
Copy link
Member

jgraham commented Jan 30, 2023

Hmm, so I don't know off the top of my head how well this approach works cross browser. It might be fine, but we'd need to discuss.

FWIW in web-platform-tests we work around this using testdriver.bless which ties the script to an actual user action. It's a bit ugly because it requires DOM manipulation to insert the <button> but it at least seems to work well enough for wpt use cases.

@foolip
Copy link
Member

foolip commented Feb 22, 2023

Perhaps we could have a way for BiDi to set the sticky activation and transient activation state, either as its own API, or just in the scope of a single script evaluation?

@OrKoN
Copy link
Contributor Author

OrKoN commented Jul 18, 2023

@jgraham I have opened a PR for this here #496 WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-discussion Issues to be discussed by the working group script Script module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants