Repository: electron/electron (language: cpp)

Issue:
[Bug]: Webview gets all the way zoomed in and its `zoomFactor` is set to `NaN`
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Electron Version

13.1.6

### What operating system are you using?

Ubuntu

### Operating System Version

Ubuntu 21.04

### What arch are you using?

x64

### Last Known Working Electron version

None. Electron 10, 11, 12, 14 are all affected, too.

### Expected Behavior

Nothing should happen

### Actual Behavior

1. Have a page with a webview with a link which includes a `#` (e.g. `<a href="#">Test link</a>`)
2. Zoom the page in via `webContents.setZoomFactor(1.1)`
3. Reset the zoom via `webContents.setZoomFactor(1.0)`
4. Click the link

The page itself stays normal while the webview gets all the way zoomed in and its `zoomFactor` is set to `NaN`.

### Testcase Gist URL

https://gist.github.com/ffflorian/2c60315bfafed606723887a7b2f21010

### Additional Information

![image](https://user-images.githubusercontent.com/5497598/125257302-93d8e300-e2fd-11eb-9a1a-a0a9fbdca258.png)


Discussion / hints:
Can repro on Ubuntu 20, but not Mac Big Sur, will test on Windows and update this comment.
@VerteDinde were you able to reproduce it on Windows? I can reproduce it on Windows 10.
@ffflorian I can! Looks like it's happening on Windows and Linux, but not MacOS - updated the labels accordingly. Also confirmed that this is still present in the latest 14 beta.
I can reproduce this on macOS Big Sur (11.5) as well:

![image](https://user-images.githubusercontent.com/5497598/126647862-8f92f36d-16f5-4d53-aa02-2dee801491c5.png)

Are there any solutions to fix this bug?
I can reproduce this on MacOS v12.1 too
I can reproduce this on macOS Monterey (12.1). In a debug build we get a CHECK() due to the NaN:

```
[43637:0120/151325.716047:FATAL:values.cc(198)] Check failed: false. Non-finite (i.e. NaN or positive/negative infinity) values cannot be represented in JSON
0   Electron Framework                  0x000000012f28a6e9 base::debug::CollectStackTrace(void**, unsigned long) + 9
1   Electron Framework                  0x000000012f1b0403 base::debug::StackTrace::StackTrace() + 19
2   Electron Framework                  0x000000012f1ca63f logging::LogMessage::~LogMessage() + 175
3   Electron Framework                  0x000000012f1cb60e logging::LogMessage::~LogMessage() + 14
4   Electron Framework                  0x000000012f27d2b3 base::Value::Value(double) + 131
5   Electron Framework                  0x000000012adb177a electron::ZoomLevelDelegate::OnZoomLevelChanged(content::HostZoomMap::ZoomLevelChange const&) + 714
6   Electron Framework                  0x000000012e063400 void base::internal::CallbackListBase<base::RepeatingCallbackList<void (content::HostZoomMap::ZoomLevelChange const&)> >::Notify<content::HostZoomMap::ZoomLevelChange&>(content::HostZoomMap::ZoomLevelChange&) + 192
7   Electron Framework                  0x000000012e0630e6 content::HostZoomMapImpl::SetZoomLevelForHostInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double, base::Time) + 534
8   Electron Framework                  0x000000012e062ec2 content::HostZoomMapImpl::SetZoomLevelForHost(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double) + 178
9   Electron Framework                  0x000000012e06185f content::HostZoomMapImpl::SetZoomLevelForWebContents(content::WebContentsImpl*, double) + 415
10  Electron Framework                  0x000000012e0616b5 content::HostZoomMap::SetZoomLevel(content::WebContents*, double) + 165
11  Electron Framework                  0x000000012adacfd8 electron::WebContentsZoomController::SetZoomLevel(double) + 1000
12  Electron Framework                  0x000000012adade70 electron::WebContentsZoomController::SetZoomFactorOnNavigationIfNeeded(GURL const&) + 448
13  Electron Framework                  0x000000012e538b7d void content::WebContentsImpl::WebContentsObserverList::NotifyObservers<void (content::WebContentsObserver::*)(content::NavigationHandle*), content::NavigationHandle*&>(void (content::WebContentsObserver::*)(content::NavigationHandle*), content::NavigationHandle*&) + 477
14  Electron Framework                  0x000000012e539174 content::WebContentsImpl::DidFinishNavigation(content::NavigationHandle*) + 100
15  Electron Framework                  0x000000012e2ed0a2 content::NavigationRequest::~NavigationRequest() + 450
16  Electron Framework                  0x000000012e2edede content::NavigationRequest::~NavigationRequest() + 14
17  Electron Framework                  0x000000012e334350 content::RenderFrameHostImpl::DidCommitNavigationInternal(std::__1::unique_ptr<content::NavigationRequest, std::__1::default_delete<content::NavigationRequest> >, mojo::StructPtr<content::mojom::DidCommitProvisionalLoadParams>, mojo::InlinedStructPtr<content::mojom::DidCommitSameDocumentNavigationParams>) + 5360
18  Electron Framework                  0x000000012e334715 content::RenderFrameHostImpl::DidCommitSameDocumentNavigation(mojo::StructPtr<content::mojom::DidCommitProvisionalLoadParams>, mojo::InlinedStructPtr<content::mojom::DidCommitSameDocumentNavigationParams>) + 741
19  Electron Framework                  0x000000012c2c2cae content::mojom::FrameHostStubDispatch::Accept(content::mojom::FrameHost*, mojo::Message*) + 4558
20  Electron Framework                  0x000000012f649a5f mojo::InterfaceEndpointClient::HandleValidatedMessage(mojo::Message*) + 639
21  Electron Framework                  0x000000012f64fcad mojo::MessageDispatcher::Accept(mojo::Message*) + 205
22  Electron Framework                  0x000000012f64b71a mojo::InterfaceEndpointClient::HandleIncomingMessage(mojo::Message*) + 154
23  Electron Framework                  0x000000012f94c5e9 IPC::(anonymous namespace)::ChannelAssociatedGroupController::AcceptOnEndpointThread(mojo::Message) + 697
24  Electron Framework                  0x000000012f9493fc base::internal::Invoker<base::internal::BindState<void (IPC::(anonymous namespace)::ChannelAssociatedGroupController::*)(mojo::Message), scoped_refptr<IPC::(anonymous namespace)::ChannelAssociatedGroupController>, mojo::Message>, void ()>::RunOnce(base::internal::BindStateBase*) + 140
25  Electron Framework                  0x000000012f222cd9 base::TaskAnnotator::RunTaskImpl(base::PendingTask&) + 313
26  Electron Framework                  0x000000012f2488f5 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl(base::sequence_manager::LazyNow*) + 981
27  Electron Framework                  0x000000012f2480cb base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() + 107
28  Electron Framework                  0x000000012f249012 non-virtual thunk to base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() + 18
29  Electron Framework                  0x000000012f2a1513 base::MessagePumpCFRunLoopBase::RunWork() + 83
30  Electron Framework                  0x000000012f2a0892 base::mac::CallWithEHFrame(void () block_pointer) + 10
31  Electron Framework                  0x000000012f2a0f4f base::MessagePumpCFRunLoopBase::RunWorkSource(void*) + 63
32  CoreFoundation                      0x00007ff8104128fd __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
33  CoreFoundation                      0x00007ff810412865 __CFRunLoopDoSource0 + 180
34  CoreFoundation                      0x00007ff8104125e4 __CFRunLoopDoSources0 + 242
35  CoreFoundation                      0x00007ff81041101b __CFRunLoopRun + 893
36  CoreFoundation                      0x00007ff8104105dd CFRunLoopRunSpecific + 563
37  HIToolbox                           0x00007ff8190434f1 RunCurrentEventLoopInMode + 292
38  HIToolbox                           0x00007ff819043247 ReceiveNextEventCommon + 587
39  HIToolbox                           0x00007ff819042fe5 _BlockUntilNextEventMatchingListInModeWithFilter + 70
40  AppKit                              0x00007ff812e3fb4c _DPSNextEvent + 886
41  AppKit                              0x00007ff812e3e1b8 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1411
42  AppKit                              0x00007ff812e305a9 -[NSApplication run] + 586
43  Electron Framework                  0x000000012f2a1f3c base::MessagePumpNSApplication::DoRun(base::MessagePump::Delegate*) + 348
44  Electron Framework                  0x000000012f2a0923 base::MessagePumpCFRunLoopBase::Run(base::MessagePump::Delegate*) + 131
45  Electron Framework                  0x000000012f249570 base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run(bool, base::TimeDelta) + 640
46  Electron Framework                  0x000000012f1fef21 base::RunLoop::Run(base::Location const&) + 913
47  Electron Framework                  0x000000012de484c3 content::BrowserMainLoop::RunMainMessageLoop() + 243
48  Electron Framework                  0x000000012de4a042 content::BrowserMainRunnerImpl::Run() + 82
49  Electron Framework                  0x000000012de457fe content::BrowserMain(content::MainFunctionParams) + 270
50  Electron Framework                  0x000000012afec4a2 content::RunBrowserProcessMain(content::MainFunctionParams, content::ContentMainDelegate*) + 258
51  Electron Framework                  0x000000012afedb8d content::ContentMainRunnerImpl::RunBrowser(content::MainFunctionParams, bool) + 1421
52  Electron Framework                  0x000000012afed51e content::ContentMainRunnerImpl::Run() + 558
53  Electron Framework                  0x000000012afeb459 content::RunContentProcess(content::ContentMainParams, content::ContentMainRunner*) + 617
54  Electron Framework                  0x000000012afebed4 content::ContentMain(content::ContentMainParams) + 84
55  Electron Framework                  0x000000012ac24d8d ElectronMain + 157
56  Electron                            0x000000010b986d1a main + 298
57  dyld
```
Bisected to https://github.com/electron/electron/compare/v8.0.0-nightly.20191017...v8.0.0-nightly.20191019. The Chromium roll in #20314 looks like the most likely suspect.
cc @jkleinsc, I know it's been a while but perhaps you remember something about that change? Looking in particular at https://github.com/electron/electron/pull/20314/commits/22daf24825a6720869c8fb53d6adf8b9fe6e3167 & the related commits in that PR
@nornagon I took a look at the code, and I can't remember that change.  For some reason, I also didn't link it to a CL, which I should have done, so sorry about that!
@nornagon the CL that required this change was 1809500: Remove the HostZoom map and IPC, and zoom limit change IPC | https://chromium-review.googlesource.com/c/chromium/src/+/1809500

Fix patch:
diff --git a/shell/browser/web_view_guest_delegate.cc b/shell/browser/web_view_guest_delegate.cc
index 792bf829dc657..8f8b24082b83a 100644
--- a/shell/browser/web_view_guest_delegate.cc
+++ b/shell/browser/web_view_guest_delegate.cc
@@ -81,7 +81,7 @@ void WebViewGuestDelegate::OnZoomLevelChanged(
       api_web_contents_->GetZoomController()->SetZoomLevel(level);
     }
     // Change the default zoom factor to match the embedders' new zoom level.
-    double zoom_factor = blink::PageZoomFactorToZoomLevel(level);
+    double zoom_factor = blink::PageZoomLevelToZoomFactor(level);
     api_web_contents_->GetZoomController()->SetDefaultZoomFactor(zoom_factor);
   }
 }


Test patch: