fix: print warning after DOM is created
This commit is contained in:
parent
714f3ffd29
commit
8716f718a9
3 changed files with 20 additions and 2 deletions
|
@ -806,9 +806,11 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {
|
||||||
|
|
||||||
void WebContents::DocumentLoadedInFrame(
|
void WebContents::DocumentLoadedInFrame(
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
if (!render_frame_host->GetParent())
|
if (!render_frame_host->GetParent()) {
|
||||||
|
is_dom_ready_ = true;
|
||||||
Emit("dom-ready");
|
Emit("dom-ready");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& validated_url) {
|
const GURL& validated_url) {
|
||||||
|
@ -834,6 +836,7 @@ void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::DidStartLoading() {
|
void WebContents::DidStartLoading() {
|
||||||
|
is_dom_ready_ = false;
|
||||||
Emit("did-start-loading");
|
Emit("did-start-loading");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1407,6 +1410,10 @@ bool WebContents::IsAudioMuted() {
|
||||||
return web_contents()->IsAudioMuted();
|
return web_contents()->IsAudioMuted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebContents::IsDOMReady() const {
|
||||||
|
return is_dom_ready_;
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::Print(mate::Arguments* args) {
|
void WebContents::Print(mate::Arguments* args) {
|
||||||
PrintSettings settings = {false, false, base::string16()};
|
PrintSettings settings = {false, false, base::string16()};
|
||||||
if (args->Length() >= 1 && !args->GetNext(&settings)) {
|
if (args->Length() >= 1 && !args->GetNext(&settings)) {
|
||||||
|
@ -2002,6 +2009,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
|
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
|
||||||
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
||||||
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
||||||
|
.SetMethod("isDomReady", &WebContents::IsDOMReady)
|
||||||
.SetMethod("undo", &WebContents::Undo)
|
.SetMethod("undo", &WebContents::Undo)
|
||||||
.SetMethod("redo", &WebContents::Redo)
|
.SetMethod("redo", &WebContents::Redo)
|
||||||
.SetMethod("cut", &WebContents::Cut)
|
.SetMethod("cut", &WebContents::Cut)
|
||||||
|
|
|
@ -142,6 +142,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
void SetIgnoreMenuShortcuts(bool ignore);
|
void SetIgnoreMenuShortcuts(bool ignore);
|
||||||
void SetAudioMuted(bool muted);
|
void SetAudioMuted(bool muted);
|
||||||
bool IsAudioMuted();
|
bool IsAudioMuted();
|
||||||
|
bool IsDOMReady() const;
|
||||||
void Print(mate::Arguments* args);
|
void Print(mate::Arguments* args);
|
||||||
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
std::vector<printing::PrinterBasicInfo> GetPrinterList();
|
||||||
void SetEmbedder(const WebContents* embedder);
|
void SetEmbedder(const WebContents* embedder);
|
||||||
|
@ -462,6 +463,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
// Whether to enable devtools.
|
// Whether to enable devtools.
|
||||||
bool enable_devtools_ = true;
|
bool enable_devtools_ = true;
|
||||||
|
|
||||||
|
// Whether page's document is ready.
|
||||||
|
bool is_dom_ready_ = false;
|
||||||
|
|
||||||
// Observers of this WebContents.
|
// Observers of this WebContents.
|
||||||
base::ObserverList<ExtendedWebContentsObserver> observers_;
|
base::ObserverList<ExtendedWebContentsObserver> observers_;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,13 @@ BrowserWindow.prototype._init = function () {
|
||||||
'"nativeWindowOpen" option will cause memory leaks, please turn off ' +
|
'"nativeWindowOpen" option will cause memory leaks, please turn off ' +
|
||||||
'the "nodeIntegration" option.\\n' +
|
'the "nodeIntegration" option.\\n' +
|
||||||
'See https://github.com/electron/electron/pull/15076 for more.'
|
'See https://github.com/electron/electron/pull/15076 for more.'
|
||||||
this.webContents.executeJavaScript(`console.warn('${message}')`)
|
// console is only available after DOM is created.
|
||||||
|
const printWarning = () => this.webContents.executeJavaScript(`console.warn('${message}')`)
|
||||||
|
if (this.webContents.isDomReady()) {
|
||||||
|
printWarning()
|
||||||
|
} else {
|
||||||
|
this.webContents.once('dom-ready', printWarning)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let {url, frameName} = urlFrameName
|
let {url, frameName} = urlFrameName
|
||||||
|
|
Loading…
Reference in a new issue