Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Referer header is not preserved when a GM_xmlhttpRequest request is redirected #2179

Closed
techmovie opened this issue Sep 22, 2024 · 2 comments

Comments

@techmovie
Copy link

Expected Behavior

Referer header is preserved when a GM_xmlhttpRequest request is redirected

Actual Behavior

The Referer header is not preserved when a GM_xmlhttpRequest request is redirected.

Specifications

  • Chromium: (128.0.6613.139)
  • TM: 5.3.0 (When I switch the TM version to 5.1.1, the Referer header can be preserved)
  • OS: MacOS 15.0

Script

// ==UserScript==
// @name referer header issue
// @version 1.0
// @description try to take over the world!
// @author Me
// @include *
// @grant GM_xmlhttpRequest
// ==/UserScript==

const fetch = (url, options) => {
  return new Promise((resolve, reject) => {
    GM_xmlhttpRequest({
      method: 'GET',
      url,
      responseType: 'json',
      ...options,
      onload: (res) => {
        const { statusText, status, response } = res;
        if (status !== 200) {
          reject(new Error(statusText || `${status}`));
        } else {
          resolve(response);
        }
      },
      ontimeout: () => {
        reject(new Error('timeout'));
      },
      onerror: (error) => {
        reject(error);
      },

    });
  });
};

const url = 'https://m.douban.com/rexxar/api/v2/movie/36205404/?for_mobile=1';
const options = {
    headers: {
        Referer: 'https://m.douban.com/movie/subject/36205404',
    },
};

fetch(url, options).then((res) => {
    console.log(res);
}).catch((error) => {
    console.error(error);
});

@derjanb
Copy link
Member

derjanb commented Sep 24, 2024

At the moment I think that this is a Chrome bug. Will add a workaround though.

@derjanb derjanb added this to the 5.3 milestone Sep 24, 2024
@derjanb
Copy link
Member

derjanb commented Sep 26, 2024

Should be fixed at 5.3.6212 (crx|xpi in review)

Please download the crx file linked above and drag and drop it to the extensions page chrome://extensions (after you've enabled 'Developer Mode').

For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants