Skip to content

Is the logic of WebClient.waitForBackgroundJavaScriptxxx() problematic? #410

@RuralHunter

Description

@RuralHunter

I mean this 2 methods:
public int waitForBackgroundJavaScript(final long timeoutMillis)
public int waitForBackgroundJavaScriptStartingBefore(final long delayMillis)

We usually do this when opening a page:

Page p=webClient.getPage(...);
webClient.waitForBackgroundJavaScriptStartingBefore(5000);

I noticed in some cases background jobs are not executed. For example with this kind of onload function:

function my_onload() {
  do_some_time_consuming_work(); //this costs like 2000ms
  setTimeout(time_func, 0);
}

In the case above, I noticed the 'time_func' sometimes executed but sometimes did not.
With waitForBackgroundJavaScriptStartingBefore(5000) I expect that all jobs run normally and those jobs started before 5000 will complete. But the fact is not that case. I checked the source and found that the waitForBackgroundJavaScriptStartingBefore locks the job manager while adding job requires that lock. So there will be no jobs added to the job queue after the waitForBackgroundJavaScriptxxx() method starts. That's not what I expected.

Is that a problem or I miss understood?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions