Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
web: Qualify global uses of location and history.
Anders Kaseorgfa91a4493c0e
diff --git a/templates/zerver/app/index.html b/templates/zerver/app/index.htmlindex a04bdf0640e..60a739ac3ed 100644--- a/templates/zerver/app/index.html+++ b/templates/zerver/app/index.html@@ -133,7 +133,7 @@<script nonce="{{ csp_nonce }}">document.addEventListener('DOMContentLoaded', function () {function reload() {- location.reload(true);+ window.location.reload(true);}document.querySelectorAll('.reload-lnk').forEach(lnk => lnk.addEventListener('click', reload));});diff --git a/web/src/billing/helpers.ts b/web/src/billing/helpers.tsindex 7b94c075784..ddbec4f2ad4 100644--- a/web/src/billing/helpers.ts+++ b/web/src/billing/helpers.ts@@ -87,10 +87,14 @@ export function create_ajax_request($(form_error).hide();$(form_success).show();if (["autopay", "invoice"].includes(form_name)) {- if ("pushState" in history) {- history.pushState("", document.title, location.pathname + location.search);+ if ("pushState" in window.history) {+ window.history.pushState(+ "",+ document.title,+ window.location.pathname + window.location.search,+ );} else {- location.hash = "";+ window.location.hash = "";}}success_callback(response);diff --git a/web/src/billing/sponsorship.ts b/web/src/billing/sponsorship.tsindex ad2537a8757..58f8b30bfc1 100644--- a/web/src/billing/sponsorship.ts+++ b/web/src/billing/sponsorship.ts@@ -111,8 +111,8 @@ $(() => {// form otherwise the sponsorship pending message is partially// hidden due to browser preserving scroll position.// https://developer.mozilla.org/en-US/docs/Web/API/History/scrollRestoration- if (history.scrollRestoration) {- history.scrollRestoration = "manual";+ if (window.history.scrollRestoration) {+ window.history.scrollRestoration = "manual";}initialize();diff --git a/web/src/browser_history.ts b/web/src/browser_history.tsindex fe86a343532..349dccc3cff 100644--- a/web/src/browser_history.ts+++ b/web/src/browser_history.ts@@ -1,4 +1,4 @@-// TODO: Rewrite this module to use history.pushState.+// TODO: Rewrite this module to use window.history.pushState.import * as blueslip from "./blueslip";import * as hash_parser from "./hash_parser";@@ -129,10 +129,10 @@ export function set_hash(hash: string): void {// Avoid adding duplicate entries in browser history.return;}- if (history.pushState) {+ if (window.history.pushState) {const url = get_full_url(hash);try {- history.pushState(null, "", url);+ window.history.pushState(null, "", url);update_web_public_hash(hash);} catch (error) {if (error instanceof TypeError) {@@ -163,12 +163,12 @@ type StateData = {export function update_current_history_state_data(new_data: StateData): void {// eslint-disable-next-line @typescript-eslint/consistent-type-assertions- const current_state = history.state as StateData | null;+ const current_state = window.history.state as StateData | null;const current_state_data = {narrow_pointer: current_state?.narrow_pointer,narrow_offset: current_state?.narrow_offset,show_more_topics: current_state?.show_more_topics,};const state_data = {...current_state_data, ...new_data};- history.replaceState(state_data, "", window.location.href);+ window.history.replaceState(state_data, "", window.location.href);}diff --git a/web/src/hashchange.js b/web/src/hashchange.jsindex 7f558be99bc..835039606df 100644--- a/web/src/hashchange.js+++ b/web/src/hashchange.js@@ -60,8 +60,8 @@ function show_all_message_view() {message_view.show([{operator: "in", operand: "home"}], {trigger: "hashchange",change_hash: false,- then_select_id: history.state?.narrow_pointer,- then_select_offset: history.state?.narrow_offset,+ then_select_id: window.history.state?.narrow_pointer,+ then_select_offset: window.history.state?.narrow_offset,});}@@ -192,7 +192,7 @@ function do_hashchange_normal(from_reload) {}}- const data_for_hash = history.state;+ const data_for_hash = window.history.state;if (data_for_hash) {narrow_opts.then_select_id = data_for_hash.narrow_pointer;narrow_opts.then_select_offset = data_for_hash.narrow_offset;@@ -281,7 +281,7 @@ function do_hashchange_overlay(old_hash) {if (base === "organization") {settings_panel_object = settings_panel_menu.org_settings;}- history.replaceState(+ window.history.replaceState(null,"",browser_history.get_full_url(base + "/" + settings_panel_object.current_tab()),@@ -300,7 +300,7 @@ function do_hashchange_overlay(old_hash) {// not match the window.location.hash, then we also reset the// base string we're tracking for the hash.if (valid_hash !== window.location.hash) {- history.replaceState(null, "", browser_history.get_full_url(valid_hash));+ window.history.replaceState(null, "", browser_history.get_full_url(valid_hash));section = hash_parser.get_current_hash_section();base = hash_parser.get_current_hash_category();}@@ -309,7 +309,7 @@ function do_hashchange_overlay(old_hash) {if (base === "groups") {const valid_hash = hash_util.validate_group_settings_hash(window.location.hash);if (valid_hash !== window.location.hash) {- history.replaceState(null, "", browser_history.get_full_url(valid_hash));+ window.history.replaceState(null, "", browser_history.get_full_url(valid_hash));section = hash_parser.get_current_hash_section();}}diff --git a/web/src/message_view.js b/web/src/message_view.jsindex 24d09338fac..f09b4761b64 100644--- a/web/src/message_view.js+++ b/web/src/message_view.js@@ -174,7 +174,7 @@ function create_and_update_message_list(filter, id_info, opts) {// workflow we have which calls `message_view.show` after hash is updated.if (opts.change_hash) {update_hash_to_match_filter(filter, opts.trigger);- opts.show_more_topics = history.state?.show_more_topics ?? false;+ opts.show_more_topics = window.history.state?.show_more_topics ?? false;}// Show the new set of messages. It is important to set message_lists.current todiff --git a/web/src/people.ts b/web/src/people.tsindex ca380ad2092..9f253847093 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -762,7 +762,7 @@ export function exclude_me_from_string(user_ids_string: string): string {}export function format_small_avatar_url(raw_url: string): string {- const url = new URL(raw_url, location.origin);+ const url = new URL(raw_url, window.location.origin);url.search += (url.search ? "&" : "") + "s=50";return url.href;}@@ -843,7 +843,7 @@ export function small_avatar_url_for_person(person: User): string {function medium_gravatar_url_for_email(email: string): string {const hash = md5(email.toLowerCase());const avatar_url = "https://secure.gravatar.com/avatar/" + hash + "?d=identicon";- const url = new URL(avatar_url, location.origin);+ const url = new URL(avatar_url, window.location.origin);url.search += (url.search ? "&" : "") + "s=500";return url.href;}diff --git a/web/src/portico/dev-login.ts b/web/src/portico/dev-login.tsindex 523f7346fb6..5d12de9ab4d 100644--- a/web/src/portico/dev-login.ts+++ b/web/src/portico/dev-login.ts@@ -4,7 +4,7 @@ $(() => {// This code will be executed when the user visits /login and// dev_login.html is rendered.if ($("[data-page-id='dev-login']").length > 0 && window.location.hash.startsWith("#")) {- /* We append the location.hash to the input field with name next so that URL can be+ /* We append the window.location.hash to the input field with name next so that URL can bepreserved after user is logged in. See this:https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */$("input[name='next']").each(function () {diff --git a/web/src/portico/landing-page.js b/web/src/portico/landing-page.jsindex 177ad0530f7..451c595dfd5 100644--- a/web/src/portico/landing-page.js+++ b/web/src/portico/landing-page.js@@ -207,7 +207,7 @@ $(document).on("click", ".pricing-tab", function () {$(".subheader-filler").attr("colspan", plans_columns_count);}- history.pushState(null, null, `#${id}`);+ window.history.pushState(null, null, `#${id}`);});$(document).on("click", ".comparison-tab", function () {diff --git a/web/src/reload_setup.js b/web/src/reload_setup.jsindex 399b73a89f6..6649e6b99c5 100644--- a/web/src/reload_setup.js+++ b/web/src/reload_setup.js@@ -10,11 +10,11 @@ import * as message_view from "./message_view";// done before the first call to get_eventsexport function initialize() {- // location.hash should be e.g. `#reload:12345123412312`- if (!location.hash.startsWith("#reload:")) {+ // window.location.hash should be e.g. `#reload:12345123412312`+ if (!window.location.hash.startsWith("#reload:")) {return;}- const hash_fragment = location.hash.slice("#".length);+ const hash_fragment = window.location.hash.slice("#".length);const trigger = "reload";// Using the token, recover the saved pre-reload data from localdiff --git a/web/src/sentry.ts b/web/src/sentry.tsindex 91d5350e4da..d23019a7af7 100644--- a/web/src/sentry.ts+++ b/web/src/sentry.ts@@ -90,7 +90,7 @@ if (page_params.server_sentry_dsn) {return {...context,metadata: {source: "custom"},- name: normalize_path(location.pathname, sentry_key === "www"),+ name: normalize_path(window.location.pathname, sentry_key === "www"),};},shouldCreateSpanForRequest,diff --git a/web/src/settings_toggle.js b/web/src/settings_toggle.jsindex c09346e0ca8..55466dd20a0 100644--- a/web/src/settings_toggle.js+++ b/web/src/settings_toggle.js@@ -62,6 +62,6 @@ export function toggle_org_setting_collapse() {// If current tab is about to be collapsed, go to default tab.const $current_tab = $(".org-settings-list .active");if ($current_tab.hasClass("hide-org-settings")) {- $(location).attr("href", "/#organization/organization-profile");+ window.location.href = "/#organization/organization-profile";}}