我正在构建一个 chrome 扩展,当从内容脚本收到某些消息时,该扩展需要进行 API 调用。我在发出 HTTP 请求时遇到困难,我相信我的 webpack 配置是罪魁祸首。
我尝试过使用node-fetchand axios,但都不适合我。
我的 webpack.common.js 文件如下所示:
const path = require("path");
module.exports = {
target: "node",
entry: {
popup: path.join(__dirname, "src/popup/index.tsx"),
background: path.join(__dirname, "src/background.ts"),
contentScript: path.join(__dirname, "src/contentScript.ts"),
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js",
},
module: {
rules: [
{
exclude: /node_modules/,
test: /\.tsx?$/,
use: "ts-loader",
},
{
exclude: /node_modules/,
test: /\.scss$/,
use: [
{
loader: "style-loader", // Creates style nodes from JS strings
},
{
loader: "css-loader", // …Run Code Online (Sandbox Code Playgroud) 我正在制作一个调用 GAS 函数的 Slack 机器人。一切正常,只是 Slack 显示错误消息,因为它在调用 API 时只等待 3 秒响应。
任何人都可以帮助我弄清楚如何异步运行 everyDay2 ,以便我可以在完成之前返回响应。我尝试过 Promise 和回调,但无法解决。
function doPost(e){
const promise = new Promise(everyDay2);
return ContentService.createTextOutput('thinking...');
}
Run Code Online (Sandbox Code Playgroud) javascript asynchronous promise google-apps-script slack-api