Skip to content

Commit 581d0ee

Browse files
Fixed duplicate calls to OnContextCreated (#5073)
* Added a reload button * Added checks for V8Context
1 parent 0c24c64 commit 581d0ee

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ namespace CefSharp
131131
_handler->OnContextCreated(% browserWrapper, % frameWrapper, % contextWrapper);
132132
}
133133

134+
//Skip additional contexts (DevTools, extensions) to avoid
135+
//double binding and duplicate calls to IRenderProcessMessageHandler.OnContextCreated
136+
//https://github.com/chromiumembedded/cef/issues/3867
137+
bool isSameContext = frame->GetV8Context()->IsSame(context);
138+
if (!isSameContext)
139+
return;
134140
auto rootObject = GetJsRootObjectWrapper(browser->GetIdentifier(), frame->GetIdentifier());
135141

136142
if (_legacyBindingEnabled)

CefSharp.Wpf.HwndHost.Example/MainWindow.xaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</Style>
2626
</Grid.Resources>
2727
<Grid.ColumnDefinitions>
28+
<ColumnDefinition Width="Auto" />
2829
<ColumnDefinition Width="Auto" />
2930
<ColumnDefinition Width="Auto" />
3031
<ColumnDefinition />
@@ -34,14 +35,15 @@
3435
</Grid.ColumnDefinitions>
3536
<Button Content="Back" Command="{Binding BackCommand, ElementName=Browser}" Width="50"/>
3637
<Button Content="Forward" Command="{Binding ForwardCommand, ElementName=Browser}" Grid.Column="1" Width="60"/>
37-
<TextBox x:Name="txtBoxAddress" Text="{Binding Address, ElementName=Browser, FallbackValue=www.google.com}" Grid.Column="2" FontSize="12" BorderBrush="Gray" BorderThickness="1">
38+
<Button Content="Reload" Command="{Binding ReloadCommand, ElementName=Browser}" Grid.Column="2" Width="60"/>
39+
<TextBox x:Name="txtBoxAddress" Text="{Binding Address, ElementName=Browser, FallbackValue=www.google.com}" Grid.Column="3" FontSize="12" BorderBrush="Gray" BorderThickness="1">
3840
<behaviors:Interaction.Behaviors>
3941
<behaviours:TextBoxBindingUpdateOnEnterBehaviour />
4042
</behaviors:Interaction.Behaviors>
4143
</TextBox>
42-
<Button Content="Print..." Command="{Binding PrintCommand, ElementName=Browser}" Grid.Column="3" Width="50" />
43-
<Button Content="View source" Command="{Binding ViewSourceCommand, ElementName=Browser}" Grid.Column="4" Width="75" />
44-
<Button Content="Show DevTools" Click="ShowDevToolsClick" Grid.Column="5" Width="100" />
44+
<Button Content="Print..." Command="{Binding PrintCommand, ElementName=Browser}" Grid.Column="4" Width="50" />
45+
<Button Content="View source" Command="{Binding ViewSourceCommand, ElementName=Browser}" Grid.Column="5" Width="75" />
46+
<Button Content="Show DevTools" Click="ShowDevToolsClick" Grid.Column="6" Width="100" />
4547
</Grid>
4648
<Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0,1">
4749
<hwndhost:ChromiumWebBrowser x:Name="Browser"

0 commit comments

Comments
 (0)