小编rob*_*007的帖子

从 Chrome 扩展程序到网页的通信

我知道可以将消息从网页发送到 chrome 扩展程序并获得返回网页的正常响应,但反过来也可能吗?

我的问题“我需要能够将请求发送到网页并等待可以在扩展中使用的响应。也许不能使用 postMessage ?”

我知道文档说“只有网页可以发起连接”。(https://developer.chrome.com/extensions/messaging#external-webpage

这是我到目前为止所尝试过的。

背景.js

chrome.extension.sendMessage("Hello from extension to webpage");
window.postMessage("Hello from extension to webpage");
chrome.tabs.sendMessage(TAB_ID, "Hello from extension to webpage");
Run Code Online (Sandbox Code Playgroud)

webpage.js(不是扩展的一部分)

window.onmessage = (event) => {
  // Waiting for that message.
  console.info("Event received ", event);
}
window.chrome.runtime.connect(CHROME_EXTENSION_APP_ID).onMessage.addListener(function (){
  function(request, sender, sendResponse) {
     console.info("Event received from the extension", event);
  }
})  
Run Code Online (Sandbox Code Playgroud)

任何想法将不胜感激:)

javascript google-chrome google-chrome-extension

7
推荐指数
1
解决办法
8002
查看次数

Redis - 在事务中使用Incr值

是否有可能使用multi.incr(value)multi.hmset

我的意思是:

var name = 'Josh';
var multi = client.multi();
multi.incr('id'); // incr => 1
multi.hmset('user:' + <need incr value here>, 'username', name);
// I want multi.hmset('user:1', 'username', 'Josh');
multi.exec(function(err,data){ .. });
Run Code Online (Sandbox Code Playgroud)

我的目标是增加'id',然后将其设置为事务中的用户ID.我已经读过,我需要做client.watch('id'),但我不明白如何使用它.

PD:请用代码发布你的答案,这是最好的方法:)

transactions redis node.js

6
推荐指数
1
解决办法
5320
查看次数

5
推荐指数
1
解决办法
1万
查看次数

将二维数组转换为交替其值的一维数组

我有一个像这样的二维数组:

let test2d = [
  ["foo", "bar"],
  ["baz", "biz"]
]
Run Code Online (Sandbox Code Playgroud)

如果我想将这个2D数组转换为1D数组(不交替它们的值),我可以通过两种方式实现:

第一种方式:

let merged = test2d.reduce( (prev, next) => prev.concat(next) )
console.log(merged) // ["foo", "bar", "baz", "biz"]
Run Code Online (Sandbox Code Playgroud)

第二种方式:

let arr1d = [].concat.apply([], test2d)
console.log(arr1d) // ["foo", "bar", "baz", "biz"]
Run Code Online (Sandbox Code Playgroud)

问题:如何获得一维数组但其值交替出现?我的意思是这样的:

["foo", "baz", "bar", "biz"]
Run Code Online (Sandbox Code Playgroud)

javascript arrays loops multidimensional-array

5
推荐指数
1
解决办法
88
查看次数

如何在 Windows 上运行多个 WSL2 实例?

我已经安装了 WSL2 并在其上部署了两台机器:

  • CentOS
  • Ubuntu-20.04

可以在我的 win10 机器上运行Ubuntu-20.04实例的多个实例吗?

ubuntu windows-subsystem-for-linux wsl-2

4
推荐指数
2
解决办法
2314
查看次数

$ scope.currentPage not updating - Angular Ui Pagination

我有这个codepen,并使用该函数'$scope.pageChanged'来查看页面何时更改.

$scope.pageChanged = function() {
 $log.log('Page changed to: ' + $scope.currentPage);
};
Run Code Online (Sandbox Code Playgroud)

但是当我点击页面链接(更改页面)时,变量'$scope.currentPage'不会改变.为什么?

我认为是有关的filter,但不确定.

javascript pagination angularjs angular-ui

3
推荐指数
1
解决办法
2404
查看次数

Nodemailer 6.1.1 不适用于 NodeJs &gt;=12

我有一个问题nodemailer,当我的更新nodejs版本12

现在,当我尝试发送电子邮件时,我得到:

DEBUG Creating transport: nodemailer (6.1.1; +https://nodemailer.com/; SMTP/6.1.1[client:6.1.1])
DEBUG Sending mail using SMTP/6.1.1[client:6.1.1]
DEBUG [9mzLKQAwcwQ] Resolved mail.mycompany.com as xxx.xxx.xxx.xxx [cache miss]
INFO  [9mzLKQAwcwQ] Connection established to xxx.xxx.xxx.xxx:587
DEBUG [9mzLKQAwcwQ] S: 220 mail.mycompany.com ESMTP
DEBUG [9mzLKQAwcwQ] C: EHLO [127.0.0.1]
DEBUG [9mzLKQAwcwQ] S: 250-mail.mycompany.com
DEBUG [9mzLKQAwcwQ] S: 250-STARTTLS
DEBUG [9mzLKQAwcwQ] S: 250-PIPELINING
DEBUG [9mzLKQAwcwQ] S: 250-8BITMIME
DEBUG [9mzLKQAwcwQ] S: 250-SIZE 23068672
DEBUG [9mzLKQAwcwQ] S: 250 AUTH LOGIN PLAIN CRAM-MD5
DEBUG [9mzLKQAwcwQ] C: STARTTLS
DEBUG [9mzLKQAwcwQ] …
Run Code Online (Sandbox Code Playgroud)

javascript node.js nodemailer

3
推荐指数
1
解决办法
4487
查看次数

如何解决Firebase功能环境中的CORS?

我遇到了CORS问题。在我的functions/index.js我有:

const cors = require('cors')({
  origin: true
});
Run Code Online (Sandbox Code Playgroud)

我的终点是https://sis-t.redsys.es:25443/sis/realizarPago。我需要POST使用来自客户端的适当参数对此URL进行操作,这是在Firebase环境之外。我也有允许外部网络的正确计划,但是向源地址以外的地址发出请求会引发CORS问题:

我已经读到您只需要修改标题,但这仅在您向自己的服务器发出请求时才适用。当您执行时http.onRequest(),您可以在函数内部使用中间件,但是对外部服务器进行POST会发生什么?

这是执行以下操作的axios功能POST

cardPay: function () {
  this.cardProcess = true
    axios({
      method: 'post',
      url: 'https://us-central1-cutre-windrider.cloudfunctions.net/cardPay',
      data: {
        verifiedUserLogged: this.userLogged.uid,
        cart: this.cartItemList,
        finalPrice: this.serverPrice,
        deliveryInfo: this.userLogged.deliveryAdress,
        name: this.userLogged.displayName || false,
        email: this.userLogged.email
      }
    })
    .then(response => {
      this.requestData = response
      this.redsysRedirect(response.data.data)
    })
    .catch(console.log)
    },
redsysRedirect: function (data) {
  axios.post('https://sis-t.redsys.es:25443/sis/realizarPago', {
    'Ds_SignatureVersion': 'HMAC_SHA256_V1',
    'Ds_MerchantParameters': data.merchantParameters,
    'Ds_Signature': …
Run Code Online (Sandbox Code Playgroud)

javascript promise firebase google-cloud-functions

2
推荐指数
3
解决办法
2185
查看次数