使用AWS服务的chrome扩展 [英] chrome extension which uses AWS services

查看:156
本文介绍了使用AWS服务的chrome扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个新的chrome扩展程序,该扩展程序应允许/阻止某些文件下载.我需要将URL发送到AWS lambda,处理文件并返回布尔值.

I'm setting up a new chrome extension that suppose to allow/block certain file download. I need to send urls to AWS lambda, process the file and return a boolean back.

我已经实现了chrome扩展部分,该部分可以监听新下载,暂停新下载并提取URL.我不知道如何将此URL发送到AWS lambda服务进行处理.我无法创建AW​​S对象以使用其服务,因为我在客户端而不是NodeJS上使用JS.

I already implemented the chrome extension part that listen to new downloads, pause them and extract the URL. I can't figure out how to send this URL to an AWS lambda service to process. I can't create an AWS object in order to use its services because I use JS on client side and not NodeJS.

import { S3, Lambda } from 'aws-sdk';

var s3 = new S3({apiVersion: '2006-03-01'});

第一行抛出错误:

未捕获的SyntaxError:意外令牌{

Uncaught SyntaxError: Unexpected token {

在我编写NodeJS语法后,我希望它能随着vscode的修复而编译:

I expected it to compile as the vscode fixed me after I wrote NodeJS syntax:

var AWS = require('aws-sdk');

然后如何从javascript chrome扩展中使用AWS服务?

How can I use AWS services from javascript chrome extension then?

推荐答案

这是您将aws-sdk用于chrome扩展的方法

This is how you use aws-sdk for chrome extensions

  1. 创建一个空的新aws.js文件.

  1. Create an empty new aws.js file.

复制粘贴 https:中的内容://sdk.amazonaws.com/js/aws-sdk-2.555.0.min.js 到我们创建的aws.js文件.

Copy paste the contents from the https://sdk.amazonaws.com/js/aws-sdk-2.555.0.min.js to the aws.js file we created.

在manifest.json中,将其添加到content_scripts中.

In manifest.json, add it inside the content_scripts.

例如"js":["aws.js","contentScript.js"]

e.g "js": ["aws.js", "contentScript.js"]

说明

Google希望您在本地提供库,因此我们创建了aws.js,并通过简单的粘贴操作将js的aws-sdk复制到了本地文件中(很长)

Google wants you to provide libraries locally, hence we create the aws.js and a simple copy-paste gets the aws-sdk for js on our local file (it's long)

如果要访问contentScript.js中的aws.js内容,请确保将aws.js添加到同一数组中.如果将其作为新的contentScript对象传递,则它们将不会共享其内容

If you want to access the contents of aws.js in your contentScript.js make sure to add the aws.js inside the same array. If you pass it as a new contentScript object they won't be sharing their content

这篇关于使用AWS服务的chrome扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆