1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/* this source code form is subject to the terms of the mozilla public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* A mapping of error message names to external documentation. Any error message
* included here will be displayed alongside its link in the web console.
*/
"use strict";
// Worker contexts do not support Services; in that case we have to rely
// on the support URL redirection.
loader.lazyGetter(this, "supportBaseURL", () => {
// Fallback URL used for worker targets, as well as when app.support.baseURL
// cannot be formatted.
let url = "https://support.mozilla.org/kb/";
if (!isWorker) {
try {
// formatURLPref might throw if tokens used in app.support.baseURL
// are not available for the current binary. See Bug 1755626.
url = Services.urlFormatter.formatURLPref("app.support.baseURL");
} catch (e) {
console.warn(
`Failed to format app.support.baseURL, falling back to ${url} (${e.message})`
);
}
}
return url;
});
const baseErrorURL =
"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Errors/";
const params =
"?utm_source=mozilla&utm_medium=firefox-console-errors&utm_campaign=default";
const ErrorDocs = {
JSMSG_READ_ONLY: "Read-only",
JSMSG_BAD_ARRAY_LENGTH: "Invalid_array_length",
JSMSG_NEGATIVE_REPETITION_COUNT: "Negative_repetition_count",
JSMSG_RESULTING_STRING_TOO_LARGE: "Resulting_string_too_large",
JSMSG_BAD_RADIX: "Bad_radix",
JSMSG_PRECISION_RANGE: "Precision_range",
JSMSG_STMT_AFTER_RETURN: "Stmt_after_return",
JSMSG_NOT_A_CODEPOINT: "Not_a_codepoint",
JSMSG_BAD_SORT_ARG: "Array_sort_argument",
JSMSG_UNEXPECTED_TYPE: "Unexpected_type",
JSMSG_NOT_DEFINED: "Not_defined",
JSMSG_NOT_FUNCTION: "Not_a_function",
JSMSG_EQUAL_AS_ASSIGN: "Equal_as_assign",
JSMSG_UNDEFINED_PROP: "Undefined_prop",
JSMSG_DEPRECATED_PRAGMA: "Deprecated_source_map_pragma",
JSMSG_DEPRECATED_USAGE: "Deprecated_caller_or_arguments_usage",
JSMSG_CANT_DELETE: "Cant_delete",
JSMSG_VAR_HIDES_ARG: "Var_hides_argument",
JSMSG_JSON_BAD_PARSE: "JSON_bad_parse",
JSMSG_UNDECLARED_VAR: "Undeclared_var",
JSMSG_UNEXPECTED_TOKEN: "Unexpected_token",
JSMSG_BAD_OCTAL: "Bad_octal",
JSMSG_PROPERTY_ACCESS_DENIED: "Property_access_denied",
JSMSG_NO_PROPERTIES: "No_properties",
JSMSG_ALREADY_HAS_PRAGMA: "Already_has_pragma",
JSMSG_BAD_RETURN_OR_YIELD: "Bad_return_or_yield",
JSMSG_UNEXPECTED_TOKEN_NO_EXPECT: "Missing_semicolon_before_statement",
JSMSG_OVER_RECURSED: "Too_much_recursion",
JSMSG_BRACKET_AFTER_LIST: "Missing_bracket_after_list",
JSMSG_PAREN_AFTER_ARGS: "Missing_parenthesis_after_argument_list",
JSMSG_MORE_ARGS_NEEDED: "More_arguments_needed",
JSMSG_BAD_LEFTSIDE_OF_ASS: "Invalid_assignment_left-hand_side",
JSMSG_UNTERMINATED_STRING: "Unterminated_string_literal",
JSMSG_NOT_CONSTRUCTOR: "Not_a_constructor",
JSMSG_CURLY_AFTER_LIST: "Missing_curly_after_property_list",
JSMSG_DEPRECATED_FOR_EACH: "For-each-in_loops_are_deprecated",
JSMSG_STRICT_NON_SIMPLE_PARAMS: "Strict_Non_Simple_Params",
JSMSG_DEAD_OBJECT: "Dead_object",
JSMSG_OBJECT_REQUIRED: "No_non-null_object",
JSMSG_IDSTART_AFTER_NUMBER: "Identifier_after_number",
JSMSG_DEPRECATED_EXPR_CLOSURE: "Deprecated_expression_closures",
JSMSG_ILLEGAL_CHARACTER: "Illegal_character",
JSMSG_BAD_REGEXP_FLAG: "Bad_regexp_flag",
JSMSG_INVALID_FOR_IN_DECL_WITH_INIT: "Invalid_for-in_initializer",
JSMSG_CANT_REDEFINE_PROP: "Cant_redefine_property",
JSMSG_COLON_AFTER_ID: "Missing_colon_after_property_id",
JSMSG_IN_NOT_OBJECT: "in_operator_no_object",
JSMSG_CURLY_AFTER_BODY: "Missing_curly_after_function_body",
JSMSG_NAME_AFTER_DOT: "Missing_name_after_dot_operator",
JSMSG_DEPRECATED_OCTAL: "Deprecated_octal",
JSMSG_PAREN_AFTER_COND: "Missing_parenthesis_after_condition",
JSMSG_JSON_CYCLIC_VALUE: "Cyclic_object_value",
JSMSG_NO_VARIABLE_NAME: "No_variable_name",
JSMSG_UNNAMED_FUNCTION_STMT: "Unnamed_function_statement",
JSMSG_CANT_DEFINE_PROP_OBJECT_NOT_EXTENSIBLE:
"Cant_define_property_object_not_extensible",
JSMSG_TYPED_ARRAY_BAD_ARGS: "Typed_array_invalid_arguments",
JSMSG_GETTER_ONLY: "Getter_only",
JSMSG_INVALID_DATE: "Invalid_date",
JSMSG_DEPRECATED_STRING_METHOD: "Deprecated_String_generics",
JSMSG_RESERVED_ID: "Reserved_identifier",
JSMSG_BAD_CONST_ASSIGN: "Invalid_const_assignment",
JSMSG_BAD_CONST_DECL: "Missing_initializer_in_const",
JSMSG_OF_AFTER_FOR_LOOP_DECL: "Invalid_for-of_initializer",
JSMSG_BAD_URI: "Malformed_URI",
JSMSG_DEPRECATED_DELETE_OPERAND: "Delete_in_strict_mode",
JSMSG_MISSING_FORMAL: "Missing_formal_parameter",
JSMSG_CANT_TRUNCATE_ARRAY: "Non_configurable_array_element",
JSMSG_INCOMPATIBLE_PROTO: "Called_on_incompatible_type",
JSMSG_INCOMPATIBLE_METHOD: "Called_on_incompatible_type",
JSMSG_BAD_INSTANCEOF_RHS: "invalid_right_hand_side_instanceof_operand",
JSMSG_EMPTY_ARRAY_REDUCE: "Reduce_of_empty_array_with_no_initial_value",
JSMSG_NOT_ITERABLE: "is_not_iterable",
JSMSG_PROPERTY_FAIL: "cant_access_property",
JSMSG_PROPERTY_FAIL_EXPR: "cant_access_property",
JSMSG_REDECLARED_VAR: "Redeclared_parameter",
JSMSG_SET_NON_OBJECT_RECEIVER: "Cant_assign_to_property",
};
const MIXED_CONTENT_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/Security/Mixed_content";
const TRACKING_PROTECTION_LEARN_MORE =
"https://developer.mozilla.org/Firefox/Privacy/Tracking_Protection";
const INSECURE_PASSWORDS_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/Security/Insecure_passwords";
const PUBLIC_KEY_PINS_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/HTTP/Public_Key_Pinning";
const STRICT_TRANSPORT_SECURITY_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/HTTP/Headers/Strict-Transport-Security";
const MIME_TYPE_MISMATCH_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Content-Type-Options";
const SOURCE_MAP_LEARN_MORE =
"https://firefox-source-docs.mozilla.org/devtools-user/debugger/source_map_errors/";
const TLS_LEARN_MORE =
"https://blog.mozilla.org/security/2018/10/15/removing-old-versions-of-tls/";
const X_FRAME_OPTIONS_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Frame-Options";
const REQUEST_STORAGE_ACCESS_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/API/Document/requestStorageAccess";
const DOCTYPE_MODES_LEARN_MORE =
"https://developer.mozilla.org/docs/Web/HTML/Quirks_Mode_and_Standards_Mode";
const ErrorCategories = {
"X-Frame-Options": X_FRAME_OPTIONS_LEARN_MORE,
"Insecure Password Field": INSECURE_PASSWORDS_LEARN_MORE,
"Mixed Content Message": MIXED_CONTENT_LEARN_MORE,
"Mixed Content Blocker": MIXED_CONTENT_LEARN_MORE,
"Invalid HPKP Headers": PUBLIC_KEY_PINS_LEARN_MORE,
"Invalid HSTS Headers": STRICT_TRANSPORT_SECURITY_LEARN_MORE,
"Tracking Protection": TRACKING_PROTECTION_LEARN_MORE,
MIMEMISMATCH: MIME_TYPE_MISMATCH_LEARN_MORE,
"source map": SOURCE_MAP_LEARN_MORE,
TLS: TLS_LEARN_MORE,
requestStorageAccess: REQUEST_STORAGE_ACCESS_LEARN_MORE,
HTTPSOnly: supportBaseURL + "https-only-prefs",
HTML_PARSER__DOCTYPE: DOCTYPE_MODES_LEARN_MORE,
};
const baseCorsErrorUrl =
"https://developer.mozilla.org/docs/Web/HTTP/CORS/Errors/";
const corsParams =
"?utm_source=devtools&utm_medium=firefox-cors-errors&utm_campaign=default";
const CorsErrorDocs = {
CORSDisabled: "CORSDisabled",
CORSDidNotSucceed2: "CORSDidNotSucceed",
CORSOriginHeaderNotAdded: "CORSOriginHeaderNotAdded",
CORSExternalRedirectNotAllowed: "CORSExternalRedirectNotAllowed",
CORSRequestNotHttp: "CORSRequestNotHttp",
CORSMissingAllowOrigin2: "CORSMissingAllowOrigin",
CORSMultipleAllowOriginNotAllowed: "CORSMultipleAllowOriginNotAllowed",
CORSAllowOriginNotMatchingOrigin: "CORSAllowOriginNotMatchingOrigin",
CORSNotSupportingCredentials: "CORSNotSupportingCredentials",
CORSMethodNotFound: "CORSMethodNotFound",
CORSMissingAllowCredentials: "CORSMissingAllowCredentials",
CORSPreflightDidNotSucceed3: "CORSPreflightDidNotSucceed",
CORSInvalidAllowMethod: "CORSInvalidAllowMethod",
CORSInvalidAllowHeader: "CORSInvalidAllowHeader",
CORSMissingAllowHeaderFromPreflight2: "CORSMissingAllowHeaderFromPreflight",
};
const baseStorageAccessPolicyErrorUrl =
"https://developer.mozilla.org/docs/Mozilla/Firefox/Privacy/Storage_access_policy/Errors/";
const storageAccessPolicyParams =
"?utm_source=devtools&utm_medium=firefox-cookie-errors&utm_campaign=default";
const StorageAccessPolicyErrorDocs = {
cookieBlockedPermission: "CookieBlockedByPermission",
cookieBlockedTracker: "CookieBlockedTracker",
cookieBlockedAll: "CookieBlockedAll",
cookieBlockedForeign: "CookieBlockedForeign",
cookiePartitionedForeign: "CookiePartitionedForeign",
};
exports.GetURL = error => {
if (!error) {
return undefined;
}
const doc = ErrorDocs[error.errorMessageName];
if (doc) {
return baseErrorURL + doc + params;
}
const corsDoc = CorsErrorDocs[error.category];
if (corsDoc) {
return baseCorsErrorUrl + corsDoc + corsParams;
}
const storageAccessPolicyDoc = StorageAccessPolicyErrorDocs[error.category];
if (storageAccessPolicyDoc) {
return (
baseStorageAccessPolicyErrorUrl +
storageAccessPolicyDoc +
storageAccessPolicyParams
);
}
const categoryURL = ErrorCategories[error.category];
if (categoryURL) {
return categoryURL + params;
}
return undefined;
};
|