TypeError: adapter is not a function
tuantmtb opened this issue · comments
Here is my code ES6:
In background:
const axios = require('axios')
const axiosChromeMessagingAdapter = require('axios-chrome-messaging-adapter')
axiosChromeMessagingAdapter.registerMessageHandler()
Content script:
import axios from 'axios'
const axiosChromeMessagingAdapter = require('axios-chrome-messaging-adapter')
const http = axios.create({
adapter: axiosChromeMessagingAdapter
})
export { http }
Error: TypeError: adapter is not a function
Could you fix this?
Please recheck version axios-chrome-messaging-adapter@0.2.1
TypeError: adapter is not a function
at dispatchRequest
Could you update code in readme if changed ?
@Gramatiik
Thank you so much!
Hello @tuantmtb,
The API did not change and the README is up to date.
Please check that the module you installed is version 0.2.1.
If the problem persist feel free to reopen the issue. 🙂
Thank you for support.
I still can not work. Could you update ES6 syntax?
My extension based on https://github.com/Kocal/vue-web-extension
Since this is something that seems a bit confusing, I will export the adapter and the message handler registration function under named exports so you can use them with both CommonJS and ES6 modules.
I will release a version 0.3.0 later today and will update the README according to those changes.
Thanks for filling this issue 🙂
Thanks for quick update <3
Currently I can not get data when make post request.
Here is my code:
background:
import axios from 'axios'
import { registerMessageHandler } from 'axios-chrome-messaging-adapter'
registerMessageHandler()
http.js
import axios from 'axios'
import { adapter } from 'axios-chrome-messaging-adapter'
const http = axios.create({
adapter: adapter
})
export { http }
content script:
import { http } from 'http'
const makePostRequestForTest = async () => {
try {
console.log('prepare makePostRequestForTest ')
const response = await http.post('https://apiv2.beecost.com/comparision/search_by_url',
{
url: '',
product_name: 'Iphone',
price: null,
display_type: 'ext'
},
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Credentials': true
}
})
console.log('response', response)
const responseData = response.data
console.log('responseData ', responseData)
} catch (e) {
console.log(e)
}
return null
}
makePostRequestForTest()
I can not receive any data or status from response
.
Hello @tuantmtb,
It looks like you have a problem with CORS and your server.
The CORS related headers you are trying to set are response headers, they must be sent by the server in response to the preflight request -- i.e. the OPTIONS
request made before the real one in order to know if CORS is allowed by your server.
Please take a look at this document to understand how CORS works.
Also, I created an issue (#3) about documenting how to debug requests/responses forwarded to the background script, I will try to update the README as soon as possible.