-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
12,493 additions
and
20,786 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DEBUG_MODE=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Build and Release Chrome Extension | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
build-and-release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Install dependencies and build extension | ||
run: | | ||
yarn install | ||
NODE_ENV=production yarn build | ||
- name: Package extension | ||
id: packExtensionDir | ||
uses: cardinalby/webext-buildtools-pack-extension-dir-action@v1 | ||
with: | ||
extensionDir: 'build' # change this to your extension build folder | ||
zipFilePath: 'build/extension.zip' | ||
|
||
- name: Sign Chrome extension | ||
uses: cardinalby/webext-buildtools-chrome-crx-action@v2 | ||
with: | ||
zipFilePath: 'build/extension.zip' | ||
crxFilePath: 'build/extension.crx' | ||
privateKey: ${{ secrets.CHROME_CRX_PRIVATE_KEY }} | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: 'build/extension.crx' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodejs 19.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"editor.formatOnSave": true | ||
} | ||
"eslint.format.enable": true, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,108 @@ | ||
<img src="src/assets/img/icon-128.png" width="64"/> | ||
|
||
# Chrome Extension Boilerplate with React 17 and Webpack 5 | ||
# Taxy AI: Full Browser Automation | ||
[Waitlist](https://docs.google.com/forms/d/e/1FAIpQLScAFKI1fZ1cXhBmSp2HM93Jvuc8Jvrxh5iSbkKhtwKN-OHoTQ/viewform) | [Discord](https://discord.gg/DXaErbBc) | ||
|
||
[![npm](https://img.shields.io/npm/v/chrome-extension-boilerplate-react)](https://www.npmjs.com/package/chrome-extension-boilerplate-react) | ||
[![npm-download](https://img.shields.io/npm/dw/chrome-extension-boilerplate-react)](https://www.npmjs.com/package/chrome-extension-boilerplate-react) | ||
[![npm](https://img.shields.io/npm/dm/chrome-extension-boilerplate-react)](https://www.npmjs.com/package/chrome-extension-boilerplate-react) | ||
Taxy uses GPT-4 to control your browser and perform repetitive actions on your behalf. Currently it allows you to define ad-hoc instructions. In the future it will also support saved and scheduled workflows. | ||
|
||
[![dependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react) | ||
[![devDependencies Status](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react/dev-status.svg)](https://david-dm.org/lxieyang/chrome-extension-boilerplate-react?type=dev) | ||
Taxy's current status is **research preview**. Many workflows fail or confuse the agent. If you'd like to hack on Taxy to make it better or test it on your own workflows, follow the instructions below to run it locally. If you'd like to know once it's available for wider usage, you can sign up for our [waitlist](https://docs.google.com/forms/d/e/1FAIpQLScAFKI1fZ1cXhBmSp2HM93Jvuc8Jvrxh5iSbkKhtwKN-OHoTQ/viewform). | ||
|
||
## Announcements | ||
Taxy is fully open-source, and we don't send any page contents or instructions to our servers. | ||
|
||
- **_This boilerplate adopts [Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/)!_** For V2 users, please check out the [manifest-v2](https://github.com/lxieyang/chrome-extension-boilerplate-react/tree/manifest-v2) branch, or use version [3.x](https://www.npmjs.com/package/chrome-extension-boilerplate-react/v/3.3.0). | ||
- Check out the [Manifest V3 Migration Guide](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/). | ||
- Recently added [devtools](https://developer.chrome.com/docs/extensions/mv3/devtools/) Support! Thanks [GeekaholicLin](https://github.com/lxieyang/chrome-extension-boilerplate-react/issues/17)! | ||
- Recently updated from **[React](https://reactjs.org)** ~~16~~ to **17**! | ||
- Recently updated from **[Webpack Dev Server](https://webpack.js.org/configuration/dev-server/)** ~~3.x~~ to **4.x** and **[Webpack](https://webpack.js.org/)** ~~4~~ to **5**! | ||
- Recently added [TypeScript](https://www.typescriptlang.org/) Support! | ||
Here's Taxy using Google Calendar with the prompt "Schedule standup tomorrow at 10am. Invite [email protected]" | ||
|
||
## Features | ||
![calendar](https://user-images.githubusercontent.com/176426/228092695-1bc11ea9-bfb7-470d-bbc6-0026e93c23c3.gif) | ||
|
||
This is a basic Chrome Extensions boilerplate to help you write modular and modern Javascript code, load CSS easily and [automatic reload the browser on code changes](https://webpack.github.io/docs/webpack-dev-server.html#automatic-refresh). | ||
|
||
This boilerplate is updated with: | ||
## Table of Contents | ||
|
||
- [Chrome Extension Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/) | ||
- [React 17](https://reactjs.org) | ||
- [Webpack 5](https://webpack.js.org/) | ||
- [Webpack Dev Server 4](https://webpack.js.org/configuration/dev-server/) | ||
- [React Hot Loader](https://github.com/gaearon/react-hot-loader) | ||
- [eslint-config-react-app](https://www.npmjs.com/package/eslint-config-react-app) | ||
- [Prettier](https://prettier.io/) | ||
- [TypeScript](https://www.typescriptlang.org/) | ||
|
||
This boilerplate is heavily inspired by and adapted from [https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate), with additional support for React 17 features, Webpack 5, and Webpack Dev Server 4. | ||
|
||
Please open up an issue to nudge me to keep the npm packages up-to-date. FYI, it takes time to make different packages with different versions work together nicely. | ||
- [Taxy AI: Full Browser Automation](#taxy-ai-full-browser-automation) | ||
- [Table of Contents](#table-of-contents) | ||
- [Installing and Running](#installing-and-running) | ||
- [Installing the extension](#installing-the-extension) | ||
- [Running in your browser](#running-in-your-browser) | ||
- [How it Works - The Action Cycle](#how-it-works---the-action-cycle) | ||
- [Simple Demos](#simple-demos) | ||
- [Protecting the main branch in GitHub](#protecting-the-main-branch-in-github) | ||
- [Searching for and playing the movie Oblivion in Netflix](#searching-for-and-playing-the-movie-oblivion-in-netflix) | ||
- [Creating a calendar event](#creating-a-calendar-event) | ||
- [Writing an essay in the OpenAI playground](#writing-an-essay-in-the-openai-playground) | ||
- [Add your own!](#add-your-own) | ||
- [Tech Stack](#tech-stack) | ||
- [Resources](#resources) | ||
|
||
## Installing and Running | ||
|
||
### Procedures: | ||
|
||
1. Check if your [Node.js](https://nodejs.org/) version is >= **14**. | ||
2. Clone this repository. | ||
3. Change the package's `name`, `description`, and `repository` fields in `package.json`. | ||
4. Change the name of your extension on `src/manifest.json`. | ||
5. Run `npm install` to install the dependencies. | ||
6. Run `npm start` | ||
7. Load your extension on Chrome following: | ||
1. Access `chrome://extensions/` | ||
2. Check `Developer mode` | ||
3. Click on `Load unpacked extension` | ||
4. Select the `build` folder. | ||
8. Happy hacking. | ||
|
||
## Structure | ||
|
||
All your extension's code must be placed in the `src` folder. | ||
|
||
The boilerplate is already prepared to have a popup, an options page, a background page, and a new tab page (which replaces the new tab page of your browser). But feel free to customize these. | ||
|
||
## TypeScript | ||
|
||
This boilerplate now supports TypeScript! The `Options` Page is implemented using TypeScript. Please refer to `src/pages/Options/` for example usages. | ||
Currently this extension is only available through this GitHub repo. We'll release it on the Chrome Web Store after adding features to increase its usability for a non-technical audience. To build and install the extension locally on your machine, follow the instructions below. | ||
|
||
## Webpack auto-reload and HRM | ||
### Installing the extension | ||
|
||
To make your workflow much more efficient this boilerplate uses the [webpack server](https://webpack.github.io/docs/webpack-dev-server.html) to development (started with `npm start`) with auto reload feature that reloads the browser automatically every time that you save some file in your editor. | ||
|
||
You can run the dev mode on other port if you want. Just specify the env var `port` like this: | ||
|
||
``` | ||
$ PORT=6002 npm run start | ||
``` | ||
|
||
## Content Scripts | ||
|
||
Although this boilerplate uses the webpack dev server, it's also prepared to write all your bundles files on the disk at every code change, so you can point, on your extension manifest, to your bundles that you want to use as [content scripts](https://developer.chrome.com/extensions/content_scripts), but you need to exclude these entry points from hot reloading [(why?)](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/issues/4#issuecomment-261788690). To do so you need to expose which entry points are content scripts on the `webpack.config.js` using the `chromeExtensionBoilerplate -> notHotReload` config. Look the example below. | ||
|
||
Let's say that you want use the `myContentScript` entry point as content script, so on your `webpack.config.js` you will configure the entry point and exclude it from hot reloading, like this: | ||
|
||
```js | ||
{ | ||
… | ||
entry: { | ||
myContentScript: "./src/js/myContentScript.js" | ||
}, | ||
chromeExtensionBoilerplate: { | ||
notHotReload: ["myContentScript"] | ||
} | ||
… | ||
} | ||
``` | ||
1. Ensure you have [Node.js](https://nodejs.org/) >= **16**. | ||
2. Clone this repository | ||
3. Run `yarn` to install the dependencies | ||
4. Run `yarn start` to build the package | ||
5. Load your extension on Chrome by doing the following: | ||
1. Navigate to `chrome://extensions/` | ||
2. Toggle `Developer mode` | ||
3. Click on `Load unpacked extension` | ||
4. Select the `build` folder that `yarn start` generated | ||
|
||
and on your `src/manifest.json`: | ||
### Running in your browser | ||
|
||
```json | ||
{ | ||
"content_scripts": [ | ||
{ | ||
"matches": ["https://www.google.com/*"], | ||
"js": ["myContentScript.bundle.js"] | ||
} | ||
] | ||
} | ||
``` | ||
1. Once installed, the browser plugin will be available in two forms: | ||
1. As a Popup. Activate by pressing `cmd+shift+y` on mac or `ctrl+shift+y` on windows/linux, or by clicking the extension logo in your browser. | ||
2. As a devtools panel. Activate by first opening the browser's developer tools, then navigating to the `Taxy AI` panel. | ||
2. The next thing you need to do is create or access an existing [OpenAI API Key](https://platform.openai.com/account/api-keys) and paste it in the provided box. This key will be stored securely in your browser, and will not be uploaded to a third party. | ||
3. Finally, navigate to a webpage you want Taxy to act upon (for instance the [OpenAI playground](https://platform.openai.com/playground)) and start experimenting! | ||
|
||
## Intelligent Code Completion | ||
## How it Works - The Action Cycle | ||
|
||
Thanks to [@hudidit](https://github.com/lxieyang/chrome-extension-boilerplate-react/issues/4)'s kind suggestions, this boilerplate supports chrome-specific intelligent code completion using [@types/chrome](https://www.npmjs.com/package/@types/chrome). | ||
1. Taxy runs a content script on the webpage to pull the entire DOM. It simplifies the html it receives to only include interactive or semantically important elements, like buttons or text. It assigns an id to each interactive element. It then "templatizes" the DOM to reduce the token count even further. | ||
2. Taxy sends the simplified DOM, along with the user's instructions, to a selected LLM (currently GPT-3.5 and GPT-4 are supported). Taxy informs the LLM of two methods to interact with the webpage: | ||
1. `click(id)` - click on the interactive element associated with that id | ||
2. `setValue(id, text)` - focus on a text input, clear its existing text, and type the specified text into that input | ||
3. When Taxy gets a completion from the LLM, it parses the response for an action. The action cycle will end at this stage if any of the following conditions are met: | ||
1. The LLM believes the task is complete. Instead of an action, the LLM can return an indication that it believes the user's task is complete based on the state of the DOM and the action history up to this point. | ||
2. The user stopped the task's execution. The user can stop the LLM's execution at any time, without waiting for it to complete. | ||
3. There was an error. Taxy's safety-first architecture causes it to automatically halt execution in the event of an unexpected response. | ||
4. Taxy executes the action using the [chrome.debugger API](https://developer.chrome.com/docs/extensions/reference/debugger/). | ||
5. The action is added to the action history and Taxy cycles back to step 1 and parses the updated DOM. All prior actions are sent to the LLM as part of the prompt used to determine the next action. Taxy can currently complete a maximum of 50 actions for a single task, though in practice most tasks require fewer than 10 actions. | ||
|
||
## Packing | ||
## Simple Demos | ||
|
||
After the development of your extension run the command | ||
### Protecting the main branch in GitHub | ||
|
||
``` | ||
$ NODE_ENV=production npm run build | ||
``` | ||
![main-branch](https://user-images.githubusercontent.com/41524992/228385404-175bf633-de1d-43eb-862c-2cfd5a7a674a.gif) | ||
|
||
Now, the content of `build` folder will be the extension ready to be submitted to the Chrome Web Store. Just take a look at the [official guide](https://developer.chrome.com/webstore/publish) to more infos about publishing. | ||
### Searching for and playing the movie Oblivion in Netflix | ||
|
||
## Secrets | ||
![Oblivion](https://user-images.githubusercontent.com/41524992/228063949-c26a4b54-92ae-4e22-8177-7e78c0d9a29b.gif) | ||
|
||
If you are developing an extension that talks with some API you probably are using different keys for testing and production. Is a good practice you not commit your secret keys and expose to anyone that have access to the repository. | ||
### Creating a calendar event | ||
|
||
To this task this boilerplate import the file `./secrets.<THE-NODE_ENV>.js` on your modules through the module named as `secrets`, so you can do things like this: | ||
![Calendar](https://user-images.githubusercontent.com/41524992/228064011-0ca3a39d-cebb-4a55-9e2b-6aa3ae5b3f43.gif) | ||
|
||
_./secrets.development.js_ | ||
### Writing an essay in the OpenAI playground | ||
|
||
```js | ||
export default { key: '123' }; | ||
``` | ||
![Playground](https://user-images.githubusercontent.com/41524992/228064056-84eab4e4-b5b5-4e79-b1e3-be92f14d2607.gif) | ||
|
||
_./src/popup.js_ | ||
### Add your own! | ||
|
||
```js | ||
import secrets from 'secrets'; | ||
ApiCall({ key: secrets.key }); | ||
``` | ||
If you have an interesting demo you'd like to share, submit a PR to add your own! | ||
|
||
:point_right: The files with name `secrets.*.js` already are ignored on the repository. | ||
## Tech Stack | ||
|
||
## Resources: | ||
Technology currently used by this extension: | ||
|
||
- [Webpack documentation](https://webpack.js.org/concepts/) | ||
- [Chrome Extension documentation](https://developer.chrome.com/extensions/getstarted) | ||
- [Chrome Extension Manifest V3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/) | ||
- [React 17](https://reactjs.org) | ||
- [Webpack 5](https://webpack.js.org/) | ||
- [Webpack Dev Server 4](https://webpack.js.org/configuration/dev-server/) | ||
- [React Hot Loader](https://github.com/gaearon/react-hot-loader) | ||
- [eslint-config-react-app](https://www.npmjs.com/package/eslint-config-react-app) | ||
- [Prettier](https://prettier.io/) | ||
- [TypeScript](https://www.typescriptlang.org/) | ||
|
||
--- | ||
## Resources | ||
|
||
Michael Xieyang Liu | [Website](https://lxieyang.github.io) | ||
- [Getting Started with Chrome Extensions](https://developer.chrome.com/extensions/getstarted) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
# Check if user provided a file name | ||
if [ -z "$1" ]; then | ||
echo "Please provide a video file name" | ||
exit 1 | ||
fi | ||
|
||
# Set default scale-down factor (proportional to video size) | ||
scale=2 | ||
|
||
# Check if user provided a scale-down parameter | ||
if [ ! -z "$2" ]; then | ||
scale=$2 | ||
fi | ||
|
||
# By default, speed up the video by 4x | ||
shorten_factor=0.25 | ||
|
||
# Check if user provided a speed-up parameter | ||
if [ ! -z "$3" ]; then | ||
shorten_factor=$3 | ||
fi | ||
|
||
# Get input file name without extension | ||
input_file="${1%.*}" | ||
|
||
# Set output file name with .gif extension | ||
output_file="$input_file.gif" | ||
|
||
# Use FFmpeg to make the GIF | ||
ffmpeg -i "$1" -vf "setpts=${shorten_factor}*PTS,fps=15,scale=iw/${scale}:ih/${scale}:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 "$output_file" | ||
|
||
echo "GIF conversion complete. Output file: $output_file" |
Oops, something went wrong.