I have this user script: [code] These are the resulting logs: [code] So the script does…
- User
I have this user script:
js// ==UserScript== // @name Intercept Requests // @namespace http://tampermonkey.net/ // @version 0.1 // @description Access OpenAI Cookie // @author You // @match https://chat.openai.com/* // @match https://*.chat.openai.com/* // @run-at document-start // @grant GM_cookie // ==/UserScript== (function() { 'use strict'; console.log("Userscript started"); // Check if token is already stored; if yes, don't intercept further if (localStorage.getItem('interceptedJWT')) { console.log("Token already stored. Exiting."); return; } // Store the original fetch function // Store both versions var originalWindowFetch = window.fetch; var originalGlobalFetch = fetch; // Override both window.fetch = modifiedFetch; fetch = modifiedFetch; function modifiedFetch(input, init = {}) { console.log("Modified fetch called with input:", input, "and init:", init); if (init && init.headers) { console.log("Headers:", init.headers); // If using Headers object, convert to plain object for easier inspection if (init.headers instanceof Headers) { let plainHeaders = {}; for (let [key, value] of init.headers.entries()) { plainHeaders[key] = value; } console.log("Converted Headers:", plainHeaders); } } // Check if the request has an "Authorization" header starting with "Bearer " if (init.headers && init.headers["Authorization"] && init.headers["Authorization"].startsWith("Bearer ")) { console.log("Has token"); localStorage.setItem('interceptedJWT', init.headers["Authorization"].split(" ")[1]); // Restore the original fetch function to stop interception once the token is stored window.fetch = originalFetch; console.log("Original fetch restored after storing token"); } else { console.log("Has no token"); } // Call the original fetch function with the provided arguments return originalFetch(input, init); }; console.log("Modified fetch set:", window.fetch); })(); - Assistant
- Usercode
Userscript started userscript.html?name=Intercept-Requests.user.js&id=0d5e9f4b-4acd-41d1-95b7-dd74e2c02f12:74 Modified fetch set: ƒ modifiedFetch(input, init = {}) { console.log("Modified fetch called with input:", input, "and init:", init); if (init && init.headers) { console.log("Headers:", init.hea… Userscript started userscript.html?name=Intercept-Requests.user.js&id=0d5e9f4b-4acd-41d1-95b7-dd74e2c02f12:74 Modified fetch set: ƒ modifiedFetch(input, init = {}) { console.log("Modified fetch called with input:", input, "and init:", init); if (init && init.headers) { console.log("Headers:", init.hea…The multiple logs are due to iframes. However, the token is not stored. This needs to be fixed.
- Assistant
- Usercode
Userscript started userscript.html?name=Intercept-Requests.user.js&id=0d5e9f4b-4acd-41d1-95b7-dd74e2c02f12:21 Running in main frame userscript.html?name=Intercept-Requests.user.js&id=0d5e9f4b-4acd-41d1-95b7-dd74e2c02f12:76 Modified fetch set: ƒ modifiedFetch(input, init = {}) { console.log("Modified fetch called with input:", input, "and init:", init); if (init && init.headers) { console.log("Headers:", init.hea… Userscript started userscript.html?name=Intercept-Requests.user.js&id=0d5e9f4b-4acd-41d1-95b7-dd74e2c02f12:21 Running in iframe userscript.html?name=Intercept-Requests.user.js&id=0d5e9f4b-4acd-41d1-95b7-dd74e2c02f12:76 Modified fetch set: ƒ modifiedFetch(input, init = {}) { console.log("Modified fetch called with input:", input, "and init:", init); if (init && init.headers) { console.log("Headers:", init.hea…The token still is not stored
- Assistant
- User
The request i want to intercept is
https://chat.openai.com/public-api/conversation_limit - Assistant