0

Similar to this question. The following userscript intercepts fetch and XMLHttpRequest requests and log their url's to the console. But, why it doesn't intercept all requests? for example it doesn't log: https://www.youtube.com/s/desktop/508deff1/img/logos/favicon.ico and https://tpc.googlesyndication.com/sodar/56-y-0RG.js

// ==UserScript==
// @name         YouTube Urls
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  URLs on YouTube.
// @author       me
// @match        https://www.youtube.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // intercept fetch requests
    const originalFetch = window.fetch;

    window.fetch = function(url, options) {

        console.log(url)
        return originalFetch(url, options);
    };


    // intercept XMLHttpRequest
    const originalXhrOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url, async, user, password) {

        console.log(url)
        return originalXhrOpen.apply(this, arguments);
    };

})();

Both resources aren't preloaded:enter image description here

EDIT:

Here are the initiator of a request, three cases in the same order marked in the image: enter image description here For the first one:

(anonymous)         @desktop_polymer.js:7320
zla                 @base.js:1425
nwa                 @base.js:2869
mya                 @base.js:3155
g.k.xz              @base.js:9573
g.k.startRendering  @base.js:9520
.
.
.
g.k.loadVideoByPlayerVars   @base.js:10439
g.k.saa                     @base.js:10612
UR.a.state.j.<computed>     @base.js:4605
(anonymous)                 @desktop_polymer.js:9647
(anonymous)                 @desktop_polymer.js:18592
acquireApi_                 @desktop_polymer.js:18592

(anonymous)                 @desktop_polymer.js:3853
(anonymous)                 @desktop_polymer.js:11370
Ov.resolveCommand           @desktop_polymer.js:5622
fmb                         @desktop_polymer.js:7712
onEndpointClick_            @desktop_polymer.js:7719
(anonymous)                 @desktop_polymer.js:3853

For the second one: enter image description here For the third one:

eval                @ VM118:1
gy                  @ VM110:1
t7                  @ VM114:1
eval                @ 5k7CCto5.html:1
Oa                  @ 5k7CCto5.html:1
M5                  @ 5k7CCto5.html:1
X                   @ 5k7CCto5.html:1
eval                            @ 5k7CCto5.html:1
requestIdleCallback.timeout     @ 5k7CCto5.html:1
requestIdleCallback
R3                     @ 5k7CCto5.html:1
M5                     @ 5k7CCto5.html:1
X                      @ 5k7CCto5.html:1
eval                   @ 5k7CCto5.html:1
requestIdleCallback.timeout     @ 5k7CCto5.html:1
requestIdleCallback
R3                     @ 5k7CCto5.html:1
M5                     @ 5k7CCto5.html:1
X                      @ 5k7CCto5.html:1
eval                   @ 5k7CCto5.html:1
requestIdleCallback.timeout     @ 5k7CCto5.html:1
requestIdleCallback
R3                     @ 5k7CCto5.html:1
M5                     @ 5k7CCto5.html:1
X                      @ 5k7CCto5.html:1
eval                   @ 5k7CCto5.html:1
requestIdleCallback.timeout @ 5k7CCto5.html:1
requestIdleCallback
R3                     @ 5k7CCto5.html:1
M5                     @ 5k7CCto5.html:1
X                      @ 5k7CCto5.html:1
eval                   @ 5k7CCto5.html:1
requestIdleCallback.timeout     @ 5k7CCto5.html:1
requestIdleCallback
R3                     @ 5k7CCto5.html:1
M5                     @ 5k7CCto5.html:1
X                      @ 5k7CCto5.html:1
.
.
.
Promise.then
C               @ 5k7CCto5.html:13
D               @ 5k7CCto5.html:13
db              @ 5k7CCto5.html:19
E               @ 5k7CCto5.html:18
(anonymous)             @ 5k7CCto5.html:13
(anonymous)             @ 5k7CCto5.html:41
(anonymous)             @ 5k7CCto5.html:37
7
  • 1
    Are they being made via XHR or fetch? Commented Nov 20, 2024 at 0:07
  • 2
    Look at the initiator of the request in devtools - it may be a DOM element (not fetch/xhr) or it may be inside the service worker or inside an iframe. Commented Nov 20, 2024 at 9:21
  • @Kosh idk, neither of the interceptors work on them Commented Nov 20, 2024 at 16:16
  • @woxxom Actually in the Size field of the Network tab says ServiceWorker router, does that mean the request was made by a service worker and cannot be intercepted? Commented Nov 20, 2024 at 18:55
  • No. Interception in your code occurs before the request is made, so that router thing is unrelated as it happens only when the request is actually made. Look at the initiator. Commented Nov 20, 2024 at 19:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.