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

CanExecuteJavascriptInMainFrame incorrectly false after loading page with different origin #3021

Closed
amaitland opened this issue Jan 23, 2020 · 8 comments
Milestone

Comments

@amaitland
Copy link
Member

amaitland commented Jan 23, 2020

  • What version of the product are you using?

79.1.310-pre

  • What architecture x86 or x64?

Both

  • On what operating system?

Win10

  • Are you using WinForms, WPF or OffScreen?

WinForms/WPF/OffScreen

Expected
After loading google.com
SetCanExecuteJavascriptOnMainFrame(true)
After loading github.com
SetCanExecuteJavascriptOnMainFrame(true)
SetCanExecuteJavascriptOnMainFrame(false)

Actual
After loading google.com
SetCanExecuteJavascriptOnMainFrame(true);
After loading github.com
SetCanExecuteJavascriptOnMainFrame(false;
SetCanExecuteJavascriptOnMainFrame(true);

The order of the process messages from the render process is sent in a different order than expected after a render process switch.

@amaitland
Copy link
Member Author

The options at this stage are

  1. Remove CanExecuteJavascriptInMainFrame
  2. Set CanExecuteJavascriptInMainFrame via a combination of FrameLoadStart/FrameLoadEnd/LoadingStateChanged

@amaitland
Copy link
Member Author

The checks are only used in the extension methods, you can directly call the relevant IFrame methods and no checks will be performed.

The extension methods execute on the main frame, call ChromiumWebBrowser.GetMainFrame() which will return an IFrame instance.

@amaitland
Copy link
Member Author

From memory the frame identifier changes on render process switch, we might be able to use this to discard the second message.

@JogyBlack
Copy link

We have a similar issue, and a workaround that we implemented is to force a reload of the browser if CanExecuteJavascriptInMainFrame is false:

...
browser.LoadingStateChanged += Browser_LoadingStateChanged;
...
private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
  if (!e.IsLoading)
  {
    if (!browser.CanExecuteJavascriptInMainFrame)
      browser.Reload();
  }
}

The immediate reloading of the page is not very noticeable, and when the reloading finishes, CanExecuteJavascriptInMainFrame is true and we can execute JS on the page.

@amaitland amaitland added this to the 81.3.x milestone May 3, 2020
amaitland added a commit that referenced this issue May 4, 2020
…false after loading page with different origin

Proof of concept for a workaround. The frameId for the second OnContextReleased that arrives after the OnContextCreated from
the old render process strangely has a frameId greater than the new frameId

TODO: Unit tests

Issue #3021
@amaitland
Copy link
Member Author

amaitland commented May 4, 2020

  • Ignore OnContextReleased that arrives after OnContextCreated when the frameId is greater.
  • Add unit tests.

@amaitland
Copy link
Member Author

The v81.3.20-pre packages are now on Nuget.org for anyone interested in testing this.

amaitland added a commit that referenced this issue May 18, 2020
…eAfterNavigatingToDifferentOrigin

Confirm CanExecuteJavascriptInMainFrame is true after navigating to a different origin

Resolves #3021
@Cloudmersive
Copy link

This was never fixed

@amaitland
Copy link
Member Author

The test case added in commit 2a62f97 passes successfully. If you are having problems please provide a failing test case (Please create a pull request).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants