Axios error : TypeError: adapter is not a function

3.2k views Asked by At

I'm making a web extension using webextension-polyfill and vuejs (axios for requesting). I needed to make requests from my content script but it threw my cors errors, so I forwarded thoses requests to the background script. But axios thew me that error : axios error

here's my manifest :

{
    "manifest_version": 3,
    "name": "Teamlock web extension",
    "description": "Teamlock web extension",
    "version": "0.0.1",
    "background": {
        "service_worker": "/background.js"
    },
    "action": {
        "default_popup": "popup.html"
    },
    "content_scripts": [
        {
            "matches": [
                "<all_urls>"
            ],
            "js": [
                "/content.js"
            ]
        }
    ],
    "permissions": [
        "tabs"
    ]
}

the way I forwarded the requests to background script :

runtime.sendMessage({method:"GET",endpoint:`/api/v1/workspace`,params:{}})
.then(res =>{
   console.log(res);
});

The listener on background script :

import {runtime} from "webextension-polyfill";
runtime.onMessage.addListener((request,sender) =>{
    console.log("bien reçu");
    return http.get(`/api/v1/workspace`)
})

the http module uses axios :

import axios from "axios"
import { storage } from "webextension-polyfill";

const service = axios.create()

// request interceptor
service.interceptors.request.use(
    async (config) => {
        const {token} = await storage.local.get("token")
        if (token) {
            config.headers["Authorization"] = `Bearer ${token}`
        }
        const {instance} = await storage.local.get("instance") 
        config.baseURL = instance;
        return config
    },
    (error) => {
        console.log(error) // for debug
        return Promise.reject(error)
    }
)
export default service

Do you have any ideas ? I found also this issue on github : https://github.com/axios/axios/issues/2968

0

There are 0 answers