tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

errordocs.js (9974B)


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