Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite0612bc

Browse files
committed
feat: WebFrameMain.unresponsiveDocumentJSCallStack
1 parenta6390b5 commite0612bc

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

‎docs/api/web-frame-main.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,29 @@ A `Boolean` representing whether the frame is detached from the frame tree. If a
241241
while the corresponding page is running any[unload][] listeners, it may become detached as the
242242
newly navigated page replaced it in the frame tree.
243243

244+
####`frame.unresponsiveDocumentJSCallStack`_Readonly__Experimental_
245+
246+
A`string` representing the JavaScript call stack of the frame while it's in an unresponsive state.
247+
248+
This can be useful to determine why the frame is unresponsive in cases where there's long-running JavaScript.
249+
For more information, see the[proposed Crash Reporting API.](https://wicg.github.io/crash-reporting/)
250+
251+
```js
252+
const {app }=require('electron')
253+
254+
app.commandLine.appendSwitch('enable-features','DocumentPolicyIncludeJSCallStacksInCrashReports')
255+
256+
app.on('web-contents-created', (_,webContents)=> {
257+
webContents.on('unresponsive', ()=> {
258+
// Wait for call stack to be collected from the renderer process
259+
setTimeout(()=> {
260+
constjsCallStack=webContents.mainFrame.unresponsiveDocumentJSCallStack
261+
console.log('Renderer unresponsive\n', jsCallStack)
262+
},10)
263+
})
264+
})
265+
```
266+
244267
[SCA]:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
245268
[`postMessage`]:https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
246269
[`MessagePortMain`]:message-port-main.md

‎shell/browser/api/electron_api_web_frame_main.cc‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#include<utility>
1010
#include<vector>
1111

12+
#include"base/feature_list.h"
1213
#include"base/logging.h"
1314
#include"base/no_destructor.h"
1415
#include"content/browser/renderer_host/render_frame_host_impl.h"// nogncheck
16+
#include"content/browser/renderer_host/render_process_host_impl.h"// nogncheck
1517
#include"content/public/browser/frame_tree_node_id.h"
1618
#include"content/public/browser/render_frame_host.h"
1719
#include"content/public/common/isolated_world_ids.h"
@@ -426,6 +428,31 @@ std::vector<content::RenderFrameHost*> WebFrameMain::FramesInSubtree() const {
426428
return frame_hosts;
427429
}
428430

431+
std::stringWebFrameMain::UnresponsiveDocumentJSCallStack()const {
432+
if (!CheckRenderFrame())
433+
return"";
434+
435+
if (!base::FeatureList::IsEnabled(
436+
blink::features::kDocumentPolicyIncludeJSCallStacksInCrashReports)) {
437+
return"";
438+
}
439+
440+
content::RenderProcessHostImpl* rph =
441+
static_cast<content::RenderProcessHostImpl*>(render_frame_->GetProcess());
442+
const std::string& unresponsive_document_javascript_call_stack =
443+
rph->GetUnresponsiveDocumentJavascriptCallStack();
444+
const blink::LocalFrameToken& unresponsive_document_token =
445+
rph->GetUnresponsiveDocumentToken();
446+
447+
if (!unresponsive_document_javascript_call_stack.empty()) {
448+
if (unresponsive_document_token == render_frame_->GetFrameToken()) {
449+
return unresponsive_document_javascript_call_stack;
450+
}
451+
}
452+
453+
return"";
454+
}
455+
429456
voidWebFrameMain::DOMContentLoaded() {
430457
Emit("dom-ready");
431458
}
@@ -475,6 +502,8 @@ void WebFrameMain::FillObjectTemplate(v8::Isolate* isolate,
475502
.SetProperty("parent", &WebFrameMain::Parent)
476503
.SetProperty("frames", &WebFrameMain::Frames)
477504
.SetProperty("framesInSubtree", &WebFrameMain::FramesInSubtree)
505+
.SetProperty("unresponsiveDocumentJSCallStack",
506+
&WebFrameMain::UnresponsiveDocumentJSCallStack)
478507
.Build();
479508
}
480509

‎shell/browser/api/electron_api_web_frame_main.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
128128
std::vector<content::RenderFrameHost*>Frames()const;
129129
std::vector<content::RenderFrameHost*>FramesInSubtree()const;
130130

131+
std::stringUnresponsiveDocumentJSCallStack()const;
132+
131133
voidDOMContentLoaded();
132134

133135
mojo::Remote<mojom::ElectronRenderer> renderer_api_;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp