Не удалось выполнить 'fetch' на 'WorkerGlobalScope'

Я пытаюсь передать переменные из файла background.js в views.py в Django. Я перепробовал много способов сделать это и написал следующий код, он вроде бы работает, но я застрял на этой ошибке. Я долго искал решение, но пока ничего не нашел

//background.js

fetch("http://127.0.0.1:8000/my_app/views")
    .then(response => response.text())
    .then(responseText => {
        // Extract the X-CSRF-TOKEN cookie from the response
        let csrfToken = getCookieValue(responseText, "csrftoken");

        // Set up the data to send to the server
        let data = {
            variable1: "value1",
            variable2: "value2"
        };

        // Make the request to the server with the X-CSRF-TOKEN header
        fetch("http://127.0.0.1:8000/my_app/views", {
            method: "POST",
            body: JSON.stringify(data),
            headers: {
                "Content-Type": "application/json",
                "X-CSRF-TOKEN": csrfToken
            }
        })
            .then(response => response.json())
            .then(responseData => {
                console.log(responseData);
            });
    });

// Helper function to extract a cookie value from a string
function getCookieValue(text, name) {
    let start = text.indexOf(name + "=") + name.length + 1;
    let end = text.indexOf(";", start);
    if (end === -1) {
        end = text.length;
    }
    return text.substring(start, end);
}

ошибка следующая:

Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Invalid value

пожалуйста, помогите мне...

Вернуться на верх