Compare commits
16 Commits
fe92d62b40
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
| 41e1c33e0e | |||
| aa2bf08255 | |||
| 54af35299d | |||
| 1a327b4aaf | |||
| 4f2b9b40f3 | |||
| 9f4fb5a101 | |||
| afa4d78a0b | |||
| d5d8c89280 | |||
| 6b9ac26f82 | |||
| 567b1ade4a | |||
| 4f21030841 | |||
| 7356cd8afd | |||
| 3aff7caf2e | |||
| 7a645494f2 | |||
| e363d79bec | |||
| 91ab1d9e7e |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,3 @@
|
||||
node_modules/
|
||||
web-ext-artifacts/
|
||||
*.swp
|
||||
package.json
|
||||
package-lock.json
|
||||
|
||||
37
README.md
37
README.md
@@ -17,17 +17,25 @@ I'm so fucking tired of retards recommending libraries that are so easily detect
|
||||
## Installation
|
||||
Install the 4play extension on a **CLEAN** Firefox install. Do **NOT** use your main profile, it will mess up your tabs and containers. Enter credentials in the extension and connect.
|
||||
|
||||
Just go get the extension on the [Firefox store](https://addons.mozilla.org/en-US/firefox/addon/4play/), or run it for development like so:
|
||||
|
||||
```sh
|
||||
npm install --global web-ext
|
||||
cd ext
|
||||
web-ext run # this will launch a new firefox instance
|
||||
```
|
||||
|
||||
Then, start the server:
|
||||
```bash
|
||||
cd server
|
||||
npm install http ws
|
||||
mkdir server && cd server
|
||||
npm install @lawlers/4play
|
||||
node hello-world.js
|
||||
```
|
||||
|
||||
## Example server script
|
||||
|
||||
```js
|
||||
const fplay = require("./fplay.js");
|
||||
const fplay = require("@lawlers/4play");
|
||||
|
||||
var port = 3030;
|
||||
var timeout = 30000;
|
||||
@@ -103,26 +111,9 @@ Gets the browser's user agent string.
|
||||
|
||||
**Returns:** `string` on success, `false` on failure.
|
||||
|
||||
## `fplay.web_response_whitelist(sources)`
|
||||
### `fplay.web_response_whitelist(sources)`
|
||||
|
||||
Outputs the response body for specific data sources. `sources` can is an array that can contain:
|
||||
|
||||
- `main_frame`
|
||||
- `sub_frame`
|
||||
- `stylesheet`
|
||||
- `script`
|
||||
- `image`
|
||||
- `object`
|
||||
- `xmlhttprequest`
|
||||
- `ping`
|
||||
- `font`
|
||||
- `media`
|
||||
- `websocket`
|
||||
- `csp_report`
|
||||
- `imageset`
|
||||
- `web_manifest`
|
||||
- `speculative`
|
||||
- `other`
|
||||
Outputs the raw body of incoming pages for `fplay.event.on("web_response", ...)`. `sources` defines what data sources will be returned: `main_frame`, `sub_frame`, `stylesheet`, `script`, `image`, `object`, `xmlhttprequest`, `ping`, `font`, `media`, `websocket`, `csp_report`, `imageset`, `web_manifest`, `speculative` and `other`
|
||||
|
||||
Default is `main_frame`, `xmlhttprequest`.
|
||||
|
||||
@@ -305,7 +296,7 @@ An `EventEmitter` instance that emits the following events:
|
||||
| `browser_connect` | `ws` | Browser connected |
|
||||
| `browser_disconnect` | `{}` | Browser disconnected |
|
||||
| `dom_ready` | `{ id, index, status, active, title, url, container }` | A tab finished loading |
|
||||
| `dom_load_fail` | `{ id }` | A tab failed to load |
|
||||
| `dom_load_fail` | `{ id, url, error }` | A tab failed to load (Network error, `<=400` code) |
|
||||
| `web_request` | `{ id, url, status, origin, type, method, container, headers }` | A request was sent |
|
||||
| `web_response` | `{ id, url, status, origin, type, method, container, body }` | A response was received |
|
||||
|
||||
|
||||
231
ext/bg.js
231
ext/bg.js
@@ -15,6 +15,8 @@ var proxy_map = {};
|
||||
|
||||
var web_response_whitelist = ["main_frame", "xmlhttprequest"];
|
||||
|
||||
var webreq_completed = new Map();
|
||||
|
||||
const log_debug = true;
|
||||
|
||||
browser.browserAction.setBadgeBackgroundColor({
|
||||
@@ -239,11 +241,25 @@ function attach_ws_events(ws){
|
||||
break;
|
||||
|
||||
case "tab_open":
|
||||
var tab =
|
||||
|
||||
// sometimes opening tabs like about:blank with a
|
||||
// container will fail.
|
||||
var tab = null;
|
||||
|
||||
try{
|
||||
tab =
|
||||
await browser.tabs.create({
|
||||
url: msg.url,
|
||||
...(typeof msg.container == "string" && { cookieStoreId: msg.container })
|
||||
});
|
||||
}catch(err){
|
||||
|
||||
// send error: we attempted to open tab
|
||||
send(ws, seqid, {
|
||||
data: false
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// immediately return even if its not loaded yet
|
||||
send(ws, seqid, {
|
||||
@@ -322,7 +338,7 @@ function attach_ws_events(ws){
|
||||
send(ws, seqid, {"status": true, "result": result});
|
||||
}catch(err){
|
||||
|
||||
send(ws, seqid, {"status": err.name + ": " + err.message});
|
||||
send(ws, seqid, {"status": err.name + ": " + err.message, "result": null});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -443,6 +459,22 @@ function attach_ws_events(ws){
|
||||
|
||||
if(status){
|
||||
|
||||
if(
|
||||
msg.proxy.type == "http" ||
|
||||
msg.proxy.type == "https"
|
||||
){
|
||||
|
||||
if(typeof msg.proxy.proxyDNS == "boolean"){
|
||||
|
||||
delete msg.proxy.proxyDNS;
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof msg.proxy.port == "string"){
|
||||
|
||||
msg.proxy.port = parseInt(msg.proxy.port);
|
||||
}
|
||||
|
||||
proxy_map[msg.id] = msg.proxy;
|
||||
send(ws, seqid, {status: true});
|
||||
return;
|
||||
@@ -473,6 +505,7 @@ function attach_ws_events(ws){
|
||||
ws.addEventListener("close", async function(e){
|
||||
|
||||
console.log("ws: offline");
|
||||
webreq_completed = new Map();
|
||||
await set_status(STATUS_OFFLINE);
|
||||
});
|
||||
}
|
||||
@@ -530,21 +563,53 @@ async function buff2b64(uint8Array) {
|
||||
});
|
||||
}
|
||||
|
||||
// store incoming data
|
||||
browser.webRequest.onBeforeRequest.addListener(
|
||||
async function(details){
|
||||
function(details){
|
||||
|
||||
if(global_ws === null){ return; }
|
||||
|
||||
if(!web_response_whitelist.includes(details.type)){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(
|
||||
web_response_whitelist.length === 0 ||
|
||||
global_ws === null
|
||||
){ return; }
|
||||
){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var resolve_func = null;
|
||||
|
||||
webreq_completed.set(
|
||||
details.requestId,
|
||||
new Promise(
|
||||
function(resolve){
|
||||
|
||||
resolve_func = resolve;
|
||||
}
|
||||
)
|
||||
|
||||
const filter = browser.webRequest.filterResponseData(
|
||||
details.requestId
|
||||
);
|
||||
|
||||
var filter = null;
|
||||
|
||||
try{
|
||||
|
||||
filter = browser.webRequest.filterResponseData(details.requestId);
|
||||
}catch(err){
|
||||
|
||||
resolve_func({success: false});
|
||||
webreq_completed.delete(details.requestId);
|
||||
return;
|
||||
}
|
||||
|
||||
var chunks = [];
|
||||
|
||||
filter.ondata = async function(event){
|
||||
filter.ondata = function(event){
|
||||
|
||||
chunks.push(event.data);
|
||||
|
||||
@@ -552,7 +617,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||
filter.write(event.data);
|
||||
};
|
||||
|
||||
filter.onstop = async function(){
|
||||
filter.onstop = function(){
|
||||
|
||||
// we got the full response data
|
||||
var len = 0;
|
||||
@@ -570,7 +635,41 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||
offset += c.byteLength;
|
||||
}
|
||||
|
||||
var b64 = await buff2b64(merged);
|
||||
resolve_func({success: true, data: merged});
|
||||
filter.close();
|
||||
};
|
||||
|
||||
filter.onerror = function(){
|
||||
|
||||
resolve_func({success: false});
|
||||
webreq_completed.delete(details.requestId);
|
||||
}
|
||||
},
|
||||
{ urls: ["<all_urls>"] },
|
||||
["blocking"]
|
||||
);
|
||||
|
||||
// detect page complete and send payloads
|
||||
browser.webRequest.onCompleted.addListener(
|
||||
async function(details){
|
||||
|
||||
if(global_ws === null){ return; }
|
||||
|
||||
var pending_req = null;
|
||||
|
||||
pending_req = await webreq_completed.get(details.requestId);
|
||||
|
||||
if(
|
||||
// not in capture group
|
||||
!pending_req ||
|
||||
// some fuckass error occured
|
||||
pending_req.success === false
|
||||
){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var b64 = await buff2b64(pending_req.data);
|
||||
|
||||
send_event(
|
||||
global_ws,
|
||||
@@ -584,17 +683,44 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||
type: details.type,
|
||||
method: details.method,
|
||||
container: details.cookieStoreId,
|
||||
url: details.url,
|
||||
body: b64
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
filter.close();
|
||||
};
|
||||
// clean up
|
||||
webreq_completed.delete(details.requestId);
|
||||
},
|
||||
{ urls: ["<all_urls>"], types: web_response_whitelist },
|
||||
["blocking"]
|
||||
{ urls: ["<all_urls>"] }
|
||||
);
|
||||
|
||||
// shit out an error when the request fails
|
||||
browser.webRequest.onErrorOccurred.addListener(
|
||||
async function(page){
|
||||
|
||||
if(global_ws === null){ return; }
|
||||
|
||||
if(!web_response_whitelist.includes(page.type)){
|
||||
|
||||
webreq_completed.delete(page.requestId);
|
||||
return;
|
||||
}
|
||||
|
||||
send_event(
|
||||
global_ws,
|
||||
{
|
||||
"action": "dom_load_fail",
|
||||
"data": {
|
||||
id: page.tabId,
|
||||
url: page.url,
|
||||
error: page.error
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
webreq_completed.delete(page.requestId);
|
||||
},
|
||||
{ urls: ["<all_urls>"] }
|
||||
);
|
||||
|
||||
browser.proxy.onRequest.addListener(function(request){
|
||||
@@ -614,9 +740,47 @@ browser.proxy.onRequest.addListener(function(request){
|
||||
urls: ["<all_urls>"]
|
||||
});
|
||||
|
||||
// Automatically handle and detect all Proxy Authentication challenges
|
||||
browser.webRequest.onAuthRequired.addListener(
|
||||
function(details){
|
||||
|
||||
// Only intercept proxy auth requests, ignore normal website auth
|
||||
if(!details.isProxy){
|
||||
return {};
|
||||
}
|
||||
|
||||
const proxy_config = proxy_map[details.cookieStoreId];
|
||||
|
||||
// Check if the assigned proxy configuration for this container includes credentials
|
||||
if(
|
||||
proxy_config &&
|
||||
(
|
||||
proxy_config.type == "http" ||
|
||||
proxy_config.type == "https"
|
||||
) &&
|
||||
proxy_config.username &&
|
||||
proxy_config.password
|
||||
){
|
||||
|
||||
return {
|
||||
authCredentials: {
|
||||
username: proxy_config.username,
|
||||
password: proxy_config.password
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// If the proxy requires auth and we have no credentials, silently cancel
|
||||
// to prevent hanging the browser with auth popup dialogs.
|
||||
return { cancel: true };
|
||||
},
|
||||
{ urls: ["<all_urls>"] },
|
||||
["blocking"]
|
||||
);
|
||||
|
||||
browser.tabs.onUpdated.addListener(function(tabid, event, tab){
|
||||
|
||||
if(connected === false){ return; }
|
||||
if(global_ws === null){ return; }
|
||||
|
||||
if(event.status === "complete"){
|
||||
|
||||
@@ -638,20 +802,49 @@ browser.tabs.onUpdated.addListener(function(tabid, event, tab){
|
||||
}
|
||||
});
|
||||
|
||||
browser.webNavigation.onErrorOccurred.addListener(function(page){
|
||||
browser.webRequest.onHeadersReceived.addListener(
|
||||
function(page){
|
||||
|
||||
if(connected === false){ return; }
|
||||
if(global_ws === null){ return; }
|
||||
|
||||
if(!web_response_whitelist.includes(page.type)){
|
||||
|
||||
return
|
||||
};
|
||||
|
||||
// send error on 4xx code
|
||||
if(page.statusCode >= 400){
|
||||
|
||||
const proxy_config = proxy_map[page.cookieStoreId];
|
||||
|
||||
if(
|
||||
proxy_config &&
|
||||
(
|
||||
proxy_config.type == "http" ||
|
||||
proxy_config.type == "https"
|
||||
) &&
|
||||
page.statusCode === 407
|
||||
){
|
||||
|
||||
// ignore http proxy auth error
|
||||
return;
|
||||
}
|
||||
|
||||
send_event(
|
||||
global_ws,
|
||||
{
|
||||
"action": "dom_load_fail",
|
||||
"data": {
|
||||
id: page.tabId
|
||||
id: page.tabId,
|
||||
url: page.url,
|
||||
error: page.statusLine.trim()
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
{ urls: ["<all_urls>"] }
|
||||
);
|
||||
|
||||
(async function(){
|
||||
await ws_init();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "4play",
|
||||
"version": "1.0",
|
||||
"version": "1.8",
|
||||
"description": "4play & dominate",
|
||||
"icons": {
|
||||
"32": "icon.png"
|
||||
|
||||
@@ -2,7 +2,7 @@ const fplay = require("./lib/fplay.js");
|
||||
|
||||
var port = 3030;
|
||||
var timeout = 30000;
|
||||
var password = "cnc";
|
||||
var password = process.env.FOURPLAY_PASSWORD || "cnc";
|
||||
|
||||
fplay.event.on("server_ready", function(){
|
||||
|
||||
@@ -52,12 +52,12 @@ fplay.event.on("browser_connect", async function(ws){
|
||||
|
||||
fplay.event.on("web_request", async function(request){
|
||||
|
||||
console.log(request);
|
||||
//console.log(request);
|
||||
});
|
||||
|
||||
fplay.event.on("web_response", async function(request){
|
||||
|
||||
fplay.event.on("web_response", async function(response){
|
||||
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
fplay.init(port, password, timeout);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
const http = require("http");
|
||||
const { WebSocketServer } = require("ws");
|
||||
|
||||
const {FOURPLAY_PORT = 3000, FOURPLAY_COMMAND_TIMEOUT = 5000, FOURPLAY_PASSWORD = "cnc"} = process.env;
|
||||
|
||||
var fplay = {};
|
||||
|
||||
fplay.PORT = 3030;
|
||||
fplay.COMMAND_TIMEOUT = 5000;
|
||||
fplay.PASSWORD = "cnc";
|
||||
fplay.PORT = FOURPLAY_PORT;
|
||||
fplay.COMMAND_TIMEOUT = FOURPLAY_COMMAND_TIMEOUT;
|
||||
fplay.PASSWORD = FOURPLAY_PASSWORD;
|
||||
|
||||
const { EventEmitter } = require("events");
|
||||
fplay.event = new EventEmitter();
|
||||
@@ -25,8 +27,6 @@ fplay.server = http.createServer(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
fplay.wss = new WebSocketServer({ server: fplay.server, path: "/" + fplay.PASSWORD });
|
||||
|
||||
fplay.seqid = 0;
|
||||
fplay.pending = new Map(); // promise map
|
||||
fplay.pending_dom_ready = new Map();
|
||||
@@ -509,7 +509,17 @@ fplay.event.on("web_request", function(page){
|
||||
|
||||
fplay.browser_connected = false;
|
||||
|
||||
fplay.wss.on("connection", async function(ws){
|
||||
fplay.init = function(port = 3030, password = "cnc", command_timeout = 5000){
|
||||
|
||||
fplay.PORT = port;
|
||||
fplay.COMMAND_TIMEOUT = command_timeout;
|
||||
fplay.PASSWORD = password;
|
||||
|
||||
fplay.server.listen(fplay.PORT, function(){
|
||||
|
||||
fplay.wss = new WebSocketServer({ server: fplay.server, path: "/" + fplay.PASSWORD });
|
||||
|
||||
fplay.wss.on("connection", async function(ws){
|
||||
|
||||
fplay.browser_connected = true;
|
||||
fplay.event.emit("browser_connect", ws);
|
||||
@@ -544,18 +554,14 @@ fplay.wss.on("connection", async function(ws){
|
||||
fplay.browser_connected = false;
|
||||
fplay.event.emit("browser_disconnect", {});
|
||||
});
|
||||
});
|
||||
|
||||
fplay.init = function(port = 3030, password = "cnc", command_timeout = 5000){
|
||||
|
||||
fplay.PORT = port;
|
||||
fplay.COMMAND_TIMEOUT = command_timeout;
|
||||
fplay.PASSWORD = password;
|
||||
|
||||
fplay.server.listen(fplay.PORT, function(){
|
||||
});
|
||||
|
||||
fplay.event.emit("server_ready", {});
|
||||
});
|
||||
}
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
process.exit();
|
||||
});
|
||||
|
||||
module.exports = fplay;
|
||||
|
||||
37
server/package-lock.json
generated
Normal file
37
server/package-lock.json
generated
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@lawlers/4play",
|
||||
"version": "1.2.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lawlers/4play",
|
||||
"version": "1.2.5",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"ws": "^8.21.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.21.2",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.2.tgz",
|
||||
"integrity": "sha512-54dMVAo4WIe6SKy3vBgN+9bJZqqQ8IMRevAkOLQALhi49qkkQDQfWdAZ8KQlXiEabw88ARXXdUrlvtbKQX+aKw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
server/package.json
Normal file
29
server/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@lawlers/4play",
|
||||
"version": "1.2.5",
|
||||
"description": "4play and dominate",
|
||||
"keywords": [
|
||||
"4play",
|
||||
"fplay",
|
||||
"foreplay",
|
||||
"browser-automation",
|
||||
"puppeteer",
|
||||
"selenium",
|
||||
"playwright",
|
||||
"firefox"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.lolcat.ca/lolcat/4play"
|
||||
},
|
||||
"license": "AGPL-3.0-only",
|
||||
"author": "lolcat",
|
||||
"type": "commonjs",
|
||||
"main": "fplay.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "^8.21.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user