Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

javascript - Opening the browser debugger fixes my CORS issue

So I have this strange issue:

I have a CORS problem when I try to fetch PNG images through Javascript to generate a PDF file. BUT this problem only occurs if my browser debugger is not displayed. If I Ctrl+Alt+I before loading my page, the problem is not encountered.

This is what I get when I don't open the debugger:

enter image description here

This is what I get when I open the debugger before loading the page:

enter image description here

The pdf I am generating correctly queries the PNGS.

For some reason, opening the browser debugger before sending my fetch request seems to fix a CORS issue.

I checked my front side and we insert CORS for all requests related to the URI I hit. This is just mind boggling.

Could it be the debugger impacting code timings? Or adding a "let cors go"?

This is the fecth code I use:

fetch(data.src, {
        "mode": "cors",
        "method": "GET",
        "headers": [
            ["Accept", "image/*"]
        ],
        "credentials": "include"
    })
    .then(function (response) {
        return response.arrayBuffer();
    })
    .then(function (buffer) {
question from:https://stackoverflow.com/questions/66049576/opening-the-browser-debugger-fixes-my-cors-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Sometimes having Chrome developer tools open (depending on the options you have selected) will change the default behaviors of your requests (for example caching) which can also affect CORS.

Do you have this checkbox checked? enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...