Skip to content

Commit

Permalink
Added support for Puppeteer request interception in cooperative inter…
Browse files Browse the repository at this point in the history
…cept mode
  • Loading branch information
lbovolini committed Jun 17, 2024
1 parent 9a9445c commit 45b1759
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 138 deletions.
132 changes: 73 additions & 59 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,79 +1,93 @@
# Created by https://www.gitignore.io

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
node_modules
# Created by https://www.toptal.com/developers/gitignore/api/intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

## Plugin-specific files:

# IntelliJ
/out/
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

### Node ###
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
### Intellij+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

# node-waf configuration
.lock-wscript
.idea/*

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
!.idea/codeStyles
!.idea/runConfigurations

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
# End of https://www.toptal.com/developers/gitignore/api/intellij+all
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/highlightedFiles.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/php.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/puppeteer-page-proxy.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

20 changes: 14 additions & 6 deletions src/core/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ const CookieHandler = require('../lib/cookies');
const { setHeaders, setAgent } = require('../lib/options');
const type = require('../util/types');

const CONTINUE_INTERCEPT_RESOLUTION_PRIORITY = 0;
const RESPOND_INTERCEPT_RESOLUTION_PRIORITY = 0;
const ABORT_INTERCEPT_RESOLUTION_PRIORITY = 0;

// Responsible for applying proxy
const requestHandler = async (request, proxy, overrides = {}) => {
if (request.isInterceptResolutionHandled()) return;
// Reject non http(s) URI schemes
if (!request.url().startsWith('http') && !request.url().startsWith('https'))
{
request.continue();
request.continue({}, CONTINUE_INTERCEPT_RESOLUTION_PRIORITY);
return;
}
const cookieHandler = new CookieHandler(request);
Expand Down Expand Up @@ -36,15 +41,17 @@ const requestHandler = async (request, proxy, overrides = {}) => {
await cookieHandler.setCookies(setCookieHeader);
response.headers['set-cookie'] = undefined;
}
await request.respond({
if (request.isInterceptResolutionHandled()) return;
request.respond({
status: response.statusCode,
headers: response.headers,
body: response.body
});
}, RESPOND_INTERCEPT_RESOLUTION_PRIORITY);
}
catch (error)
{
await request.abort();
if (request.isInterceptResolutionHandled()) return;
request.abort('failed', ABORT_INTERCEPT_RESOLUTION_PRIORITY);
}
};

Expand All @@ -55,7 +62,7 @@ const removeRequestListener = (page, listenerName) => {

const useProxyPer = {
// Call this if request object passed
httprequest: async (request, data) => {
cdphttprequest: async (request, data) => {
let proxy, overrides;
// Separate proxy and overrides
if (type(data) === 'object')
Expand All @@ -78,7 +85,8 @@ const useProxyPer = {
}
else
{
request.continue(overrides);
if (request.isInterceptResolutionHandled()) return;
request.continue(overrides, CONTINUE_INTERCEPT_RESOLUTION_PRIORITY);
}
},

Expand Down

0 comments on commit 45b1759

Please sign in to comment.