chrome extension which uses AWS services

雨燕双飞 提交于 2020-01-25 07:47:32

问题


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.

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'});

First line throws error:

Uncaught SyntaxError: Unexpected token {

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

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

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


回答1:


This is how you use aws-sdk for chrome extensions

  1. Create an empty new aws.js file.

  2. 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.

  3. In manifest.json, add it inside the content_scripts.

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

Explanation

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)

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



来源:https://stackoverflow.com/questions/57893562/chrome-extension-which-uses-aws-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!