forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add chrome://webuijsexception debugging page
Add a debugging chrome:// URL that loads a page with JavaScript that just throws some exceptions. This will be used to test the WebUI JavaScript Error Reporting feature, both manually and in integration tests. This page is currently Linux + Chrome OS only. It may be added to Windows in a future CL if https://crbug.com/1129544 is fixed and the general WebUI JS Error Reporting feature gets Windows support. Bug: chromium:1121816 Change-Id: I3d7e29c15d6af9a863b023d900ced5d8c542d12d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473157 Reviewed-by: Nico Weber <thakis@chromium.org> Reviewed-by: Kyle Horimoto <khorimoto@chromium.org> Commit-Queue: Ian Barkley-Yeung <iby@chromium.org> Cr-Commit-Position: refs/heads/master@{#818036}
- Loading branch information
Showing
15 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2020 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//chrome/browser/resources/optimize_webui.gni") | ||
import("//third_party/closure_compiler/compile_js.gni") | ||
import("//tools/grit/grit_rule.gni") | ||
import("//ui/webui/webui_features.gni") | ||
|
||
js_library("webui_js_exception") { | ||
} | ||
|
||
if (optimize_webui) { | ||
grit("flattened_resources") { | ||
source = "webui_js_exception_resources.grd" | ||
|
||
deps = [ ":webui_js_exception" ] | ||
|
||
grit_flags = [ | ||
"-E", | ||
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir), | ||
] | ||
|
||
outputs = [ | ||
"grit/webui_js_exception_resources.h", | ||
"grit/webui_js_exception_resources_map.cc", | ||
"grit/webui_js_exception_resources_map.h", | ||
"webui_js_exception_resources.pak", | ||
] | ||
output_dir = "$root_gen_dir/chrome/browser/resources/webui_js_exception" | ||
} | ||
|
||
unpak("unpak") { | ||
pak_file = "webui_js_exception_resources.pak" | ||
out_folder = "unpak" | ||
deps = [ ":flattened_resources" ] | ||
} | ||
|
||
optimize_webui("build") { | ||
host = "webui_js_exception" | ||
input = rebase_path("$target_gen_dir/unpak", root_build_dir) | ||
deps = [ | ||
":unpak", | ||
"//ui/webui/resources:modulize", | ||
] | ||
js_module_in_files = [ "webui_js_exception.js" ] | ||
js_out_files = [ "webui_js_exception.rollup.js" ] | ||
excludes = [ "chrome://resources/js/cr.m.js" ] | ||
} | ||
} | ||
|
||
js_type_check("closure_compile") { | ||
deps = [ ":webui_js_exception" ] | ||
} |
25 changes: 25 additions & 0 deletions
25
chrome/browser/resources/webui_js_exception/webui_js_exception.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<!-- Title is not localized since this is just a debugging page --> | ||
<title>WebUI JS Exception Page</title> | ||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
overflow: hidden; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<!-- Text not localized since this is just a debugging page --> | ||
This page generates a JavaScript exception on load and then another 3 | ||
seconds later. | ||
<script type="module" src="webui_js_exception.js"></script> | ||
</body> | ||
</html> |
45 changes: 45 additions & 0 deletions
45
chrome/browser/resources/webui_js_exception/webui_js_exception.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/** | ||
* @fileoverview This JavaScript throws an unhandled exception on page load, and | ||
* then another 3 seconds later. | ||
* | ||
* Note that function names and error text are referenced in integration tests | ||
* (particularly tast tests); do not change them without updating the tests. | ||
*/ | ||
|
||
/** | ||
* Throws an exception when called. This throws the "after 3 seconds" exception. | ||
*/ | ||
function throwExceptionAfterTimeoutFunction() { | ||
throwExceptionAfterTimeoutInner(); | ||
} | ||
|
||
/** | ||
* Throws an exception when called. This is a separate function from | ||
* throwExceptionAfterTimeoutFunction() so that we get an interesting stack. | ||
*/ | ||
function throwExceptionAfterTimeoutInner() { | ||
throw new Error('WebUI JS Exception: timeout expired'); | ||
} | ||
|
||
/** | ||
* Throws an exception when called. This throws the "during page load" | ||
* exception. | ||
*/ | ||
function throwExceptionDuringPageLoadFunction() { | ||
throwExceptionDuringPageLoadInner(); | ||
} | ||
|
||
/** | ||
* Throws an exception when called. This is a separate function from | ||
* throwExceptionDuringPageLoadFunction() so that we get an interesting stack. | ||
*/ | ||
function throwExceptionDuringPageLoadInner() { | ||
throw new Error('WebUI JS Exception: exception on page load'); | ||
} | ||
|
||
setTimeout(throwExceptionAfterTimeoutFunction, 3000); | ||
throwExceptionDuringPageLoadFunction(); |
21 changes: 21 additions & 0 deletions
21
chrome/browser/resources/webui_js_exception/webui_js_exception_resources.grd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false"> | ||
<outputs> | ||
<output filename="grit/webui_js_exception_resources.h" type="rc_header"> | ||
<emit emit_type='prepend'></emit> | ||
</output> | ||
<output filename="grit/webui_js_exception_resources_map.cc" | ||
type="resource_file_map_source" /> | ||
<output filename="grit/webui_js_exception_resources_map.h" | ||
type="resource_map_header" /> | ||
<output filename="webui_js_exception_resources.pak" type="data_package" /> | ||
</outputs> | ||
<release seq="1"> | ||
<structures> | ||
<structure name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_JS" | ||
file="webui_js_exception.js" type="chrome_html" compress="false" /> | ||
<structure name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML" | ||
file="webui_js_exception.html" type="chrome_html" compress="false" /> | ||
</structures> | ||
</release> | ||
</grit> |
22 changes: 22 additions & 0 deletions
22
chrome/browser/resources/webui_js_exception/webui_js_exception_resources_vulcanized.grd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false"> | ||
<outputs> | ||
<output filename="grit/webui_js_exception_resources.h" type="rc_header"> | ||
<emit emit_type='prepend'></emit> | ||
</output> | ||
<output filename="grit/webui_js_exception_resources_map.cc" | ||
type="resource_map_source" /> | ||
<output filename="grit/webui_js_exception_resources_map.h" | ||
type="resource_map_header" /> | ||
<output filename="webui_js_exception_resources.pak" type="data_package" /> | ||
</outputs> | ||
<release seq="1"> | ||
<includes> | ||
<include name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_ROLLUP_JS" | ||
file="${root_gen_dir}/chrome/browser/resources/webui_js_exception/webui_js_exception.rollup.js" | ||
use_base_dir="false" type="BINDATA" /> | ||
<include name="IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML" | ||
file="webui_js_exception.html" preprocess="true" type="BINDATA" /> | ||
</includes> | ||
</release> | ||
</grit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h" | ||
|
||
#include <ios> | ||
|
||
#include "base/feature_list.h" | ||
#include "base/logging.h" | ||
#include "build/build_config.h" | ||
#include "build/buildflag.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/webui/webui_util.h" | ||
#include "chrome/common/buildflags.h" | ||
#include "chrome/common/webui_url_constants.h" | ||
#include "chrome/grit/webui_js_exception_resources.h" | ||
#include "chrome/grit/webui_js_exception_resources_map.h" | ||
#include "content/public/browser/web_ui_data_source.h" | ||
#include "content/public/common/content_features.h" | ||
|
||
#if !BUILDFLAG(OPTIMIZE_WEBUI) | ||
namespace { | ||
constexpr char kGeneratedPath[] = | ||
"@out_folder@/gen/chrome/browser/resources/webui_js_exception/"; | ||
} // namespace | ||
#endif // !BUILDFLAG(OPTIMIZE_WEBUI) | ||
|
||
WebUIJsExceptionUI::WebUIJsExceptionUI(content::WebUI* web_ui) | ||
: content::WebUIController(web_ui) { | ||
#if !defined(OS_WIN) && !defined(OS_FUCHSIA) | ||
VLOG(3) << std::boolalpha << "chrome://webuijsexception loading. " | ||
<< "Experiment state: send javascript errors is " | ||
<< base::FeatureList::IsEnabled( | ||
features::kSendWebUIJavaScriptErrorReports) | ||
<< " and send to prod is " | ||
<< features::kWebUIJavaScriptErrorReportsSendToProductionParam.Get(); | ||
#else | ||
VLOG(3) << std::boolalpha << "chrome://webuijsexception loading."; | ||
#endif | ||
|
||
content::WebUIDataSource* source = | ||
content::WebUIDataSource::Create(chrome::kChromeUIWebUIJsExceptionHost); | ||
#if BUILDFLAG(OPTIMIZE_WEBUI) | ||
webui::SetupBundledWebUIDataSource( | ||
source, "webui_js_exception.js", | ||
IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_ROLLUP_JS, | ||
IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML); | ||
#else // if !BUILDFLAG(OPTIMIZE_WEBUI) | ||
webui::SetupWebUIDataSource( | ||
source, | ||
base::make_span(kWebuiJsExceptionResources, | ||
kWebuiJsExceptionResourcesSize), | ||
kGeneratedPath, IDR_WEBUI_JS_EXCEPTION_UI_WEBUI_JS_EXCEPTION_HTML); | ||
#endif // !BUILDFLAG(OPTIMIZE_WEBUI) | ||
Profile* profile = Profile::FromWebUI(web_ui); | ||
content::WebUIDataSource::Add(profile, source); | ||
} | ||
|
||
WebUIJsExceptionUI::~WebUIJsExceptionUI() = default; | ||
|
||
WEB_UI_CONTROLLER_TYPE_IMPL(WebUIJsExceptionUI) |
22 changes: 22 additions & 0 deletions
22
chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_ | ||
|
||
#include "content/public/browser/web_ui_controller.h" | ||
|
||
// The WebUI that controls chrome://webuijsexception. | ||
class WebUIJsExceptionUI : public content::WebUIController { | ||
public: | ||
explicit WebUIJsExceptionUI(content::WebUI* web_ui); | ||
~WebUIJsExceptionUI() override; | ||
WebUIJsExceptionUI(const WebUIJsExceptionUI&) = delete; | ||
WebUIJsExceptionUI& operator=(const WebUIJsExceptionUI&) = delete; | ||
|
||
private: | ||
WEB_UI_CONTROLLER_TYPE_DECL(); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_WEBUI_JS_EXCEPTION_WEBUI_JS_EXCEPTION_UI_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.