Commit 67d4b9b4 authored by Ian Barkley-Yeung's avatar Ian Barkley-Yeung Committed by Commit Bot

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/+/2473157Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Ian Barkley-Yeung <iby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818036}
parent 1c2c60bf
......@@ -1369,6 +1369,10 @@ group("extra_resources") {
]
}
if (is_linux || is_chromeos) {
public_deps += [ "//chrome/browser/resources:webui_js_exception_resources" ]
}
if (!is_android && !is_chromeos) {
public_deps += [
"//chrome/browser/resources:profile_picker_resources",
......
......@@ -60,6 +60,9 @@ if (enable_js_type_check) {
if (is_win || is_android || is_linux || is_chromeos) {
deps += [ "sandbox_internals:closure_compile" ]
}
if (is_linux || is_chromeos) {
deps += [ "webui_js_exception:closure_compile" ]
}
if (is_chromeos) {
deps += [
"chromeos:closure_compile",
......@@ -690,6 +693,33 @@ if (enable_webui_tab_strip) {
}
}
if (is_linux || is_chromeos) {
grit("webui_js_exception_resources") {
if (optimize_webui) {
source = "webui_js_exception/webui_js_exception_resources_vulcanized.grd"
deps = [ "//chrome/browser/resources/webui_js_exception:build" ]
} else {
source = "webui_js_exception/webui_js_exception_resources.grd"
deps =
[ "//chrome/browser/resources/webui_js_exception:webui_js_exception" ]
}
grit_flags = [
"-E",
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]
defines = chrome_grit_defines
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"
}
}
repack("dev_ui_paks") {
output = "$root_gen_dir/chrome/dev_ui_resources.pak"
......
# 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" ]
}
<!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>
// 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();
<?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>
<?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>
......@@ -3296,6 +3296,8 @@ static_library("ui") {
"webui/certificate_viewer_ui.h",
"webui/certificate_viewer_webui.cc",
"webui/certificate_viewer_webui.h",
"webui/webui_js_exception/webui_js_exception_ui.cc",
"webui/webui_js_exception/webui_js_exception_ui.h",
]
if (use_aura) {
deps += [ "//third_party/fontconfig" ]
......
......@@ -230,6 +230,10 @@
#include "chrome/browser/ui/webui/app_launcher_page_ui.h"
#endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#include "chrome/browser/ui/webui/webui_js_exception/webui_js_exception_ui.h"
#endif
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
#include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/webui/browser_switch/browser_switch_ui.h"
......@@ -751,6 +755,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
}
#endif // !defined(OFFICIAL_BUILD)
#endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
if (url.host_piece() == chrome::kChromeUIWebUIJsExceptionHost)
return &NewWebUI<WebUIJsExceptionUI>;
#endif
#if defined(OS_ANDROID)
if (url.host_piece() == chrome::kChromeUIExploreSitesInternalsHost &&
!profile->IsOffTheRecord())
......
// 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)
// 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_
......@@ -221,6 +221,10 @@ template("chrome_extra_paks") {
]
}
}
if (is_linux || is_chromeos) {
sources += [ "$root_gen_dir/chrome/webui_js_exception_resources.pak" ]
deps += [ "//chrome/browser/resources:webui_js_exception_resources" ]
}
if (!is_android && !is_chromeos) {
sources += [
"$root_gen_dir/chrome/profile_picker_resources.pak",
......
......@@ -338,6 +338,11 @@ bool IsSystemWebUIHost(base::StringPiece host) {
}
#endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
const char kChromeUIWebUIJsExceptionHost[] = "webuijsexception";
const char kChromeUIWebUIJsExceptionURL[] = "chrome://webuijsexception/";
#endif
#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
const char kChromeUIDiscardsHost[] = "discards";
......@@ -608,6 +613,9 @@ const char* const kChromeDebugURLs[] = {
#if defined(OS_ANDROID)
content::kChromeUIGpuJavaCrashURL,
kChromeUIJavaCrashURL,
#endif
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
kChromeUIWebUIJsExceptionURL,
#endif
kChromeUIQuitURL,
kChromeUIRestartURL};
......
......@@ -291,6 +291,11 @@ bool IsSystemWebUIHost(base::StringPiece host);
#endif // defined(OS_CHROMEOS)
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
extern const char kChromeUIWebUIJsExceptionHost[];
extern const char kChromeUIWebUIJsExceptionURL[];
#endif
#if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
extern const char kChromeUIDiscardsHost[];
......
......@@ -265,6 +265,13 @@
"chrome/browser/resources/webapks/webapks_ui_resources.grd": {
"includes": [2220],
},
"chrome/browser/resources/webui_js_exception/webui_js_exception_resources.grd": {
"includes": [2230],
"structures": [2231],
},
"chrome/browser/resources/webui_js_exception/webui_js_exception_resources_vulcanized.grd": {
"includes": [2232],
},
"components/sync/driver/resources.grd": {
"includes": [2240],
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment