Skip to content

Commit 48b75b9

Browse files
committed
Check if djdt-store-id is in all headers before usage.
Chromium throws an uncatchable warning when a header that can't be accessed is used. While it's not problematic, it's worrisome to developers. This avoids that by first checking that it exists. Fixes #1647
1 parent 97a9165 commit 48b75b9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,13 @@ const djdt = {
264264
const origOpen = XMLHttpRequest.prototype.open;
265265
XMLHttpRequest.prototype.open = function () {
266266
this.addEventListener("load", function () {
267-
let store_id = this.getResponseHeader("djdt-store-id");
268-
if (store_id !== null) {
267+
// Chromium emits a "Refused to get unsafe header" uncatchable warning
268+
// when the header can't be fetched. While it doesn't impede execution
269+
// it's worrisome to developers.
270+
if (
271+
this.getAllResponseHeaders().indexOf("djdt-store-id") >= 0
272+
) {
273+
let store_id = this.getResponseHeader("djdt-store-id");
269274
store_id = encodeURIComponent(store_id);
270275
const dest = `${sidebar_url}?store_id=${store_id}`;
271276
slowjax(dest).then(function (data) {

0 commit comments

Comments
 (0)