Comments (18)
I will make this feature request after major updates have been added.
Thank you very much.
from puppeteer-real-browser.
Thank you. This is a much needed feature. Might be best to allow overriding the whole launch call for more flexibility.
from puppeteer-real-browser.
I will make this feature request after major updates have been added.
from puppeteer-real-browser.
@zfcsoftware I see there are many requests for an ad-blocking feature when opening the browser. Please prioritize implementing it! Thank you very much for this useful and wonderful source code.
from puppeteer-real-browser.
I guess its because the page already created, thus the plugin is not registered properly on that initial page
you can try add adblocker.onPageCreated(page)
after var page = page[0]
you can also check my fork:
https://github.com/eindrawan/puppeteer-real-browser/blob/main/src/index.js
@zfcsoftware may I create a PR for this?
from puppeteer-real-browser.
@zfcsoftware I see there are many requests for an ad-blocking feature when opening the browser. Please prioritize implementing it! Thank you very much for this useful and wonderful source code.
I will add support in a few days.
from puppeteer-real-browser.
thank bro
from puppeteer-real-browser.
Hello,
you will need to modify the library files for this. First you need to set the tf variable to false when starting the browser and then set it to true with settarget. Then you can add the plugins you want to the index.js file of the library.
https://github.com/zfcsoftware/puppeteer-real-browser/blob/main/src/index.js
import { connect } from 'puppeteer-real-browser'
connect({
tf: false, // If a feature you want to use at startup is not working, you can initialize the tf variable false and update it later.
turnstile: true
})
.then(async response => {
const { page, browser, setTarget } = response
setTarget({ status: true })
page.goto('https://nopecha.com/demo/cloudflare', {
waitUntil: 'domcontentloaded'
})
})
from puppeteer-real-browser.
import { startSession, closeSession } from './module/chromium.js'
import puppeteer from 'puppeteer-extra';
import { notice, slugify } from './module/general.js'
import { autoSolve, setSolveStatus } from './module/turnstile.js'
import { fp } from './module/afp.js';
import { puppeteerRealBrowser } from './module/old.js'
import AdblockerPlugin from "puppeteer-extra-plugin-adblocker";
export { puppeteerRealBrowser };
const adblocker = AdblockerPlugin({
blockTrackers: true, // default: false
useCache: true,
})
var global_target_status = true
function targetFilter({ target, skipTarget }) {
if (global_target_status === false) {
return true
}
var response = !!target.url()
if (skipTarget.find(item => String(target.url()).indexOf(String(item) > -1))) {
response = true
}
return response;
}
async function handleNewPage(page) {
fp(page);
return page
}
const setTarget = ({ status = true }) => {
global_target_status = status
}
export const connect = ({ args = [], headless = 'auto', customConfig = {}, proxy = {}, skipTarget = [], fingerprint = true, turnstile = false, connectOption = {}, tf = true }) => {
return new Promise(async (resolve, reject) => {
global_target_status = tf
const { chromeSession, cdpSession, chrome, xvfbsession } = await startSession({
args: args,
headless: headless,
customConfig: customConfig,
proxy: proxy
})
puppeteer.use(adblocker); //added adblocker here
console.log("Changes working");
const browser = await puppeteer.connect({
targetFilter: (target) => targetFilter({ target: target, skipTarget: skipTarget }),
browserWSEndpoint: chromeSession.browserWSEndpoint,
...connectOption
});
var page = await browser.pages()
page = page[0]
if (proxy && proxy.username && proxy.username.length > 0) {
await page.authenticate({ username: proxy.username, password: proxy.password });
}
if (fingerprint === true) {
handleNewPage(page);
}
if (turnstile === true) {
setSolveStatus({ status: true })
autoSolve({ page: page, browser: browser })
}
await page.setUserAgent(chromeSession.agent);
await page.setViewport({
width: 1920,
height: 1080
});
browser.on('disconnected', async () => {
notice({
message: 'Browser Disconnected',
type: 'info'
})
setSolveStatus({ status: false })
await closeSession({
xvfbsession: xvfbsession,
cdpSession: cdpSession,
chrome: chrome
})
});
browser.on('targetcreated', async target => {
var newPage = await target.page();
try {
await newPage.setUserAgent(chromeSession.agent);
} catch (err) {
// console.log(err.message);
}
try {
await newPage.setViewport({
width: 1920,
height: 1080
});
} catch (err) {
// console.log(err.message);
}
if (newPage && fingerprint === true) {
try {
handleNewPage(newPage);
} catch (err) { }
}
if (turnstile === true) {
autoSolve({ page: newPage })
}
});
resolve({
browser: browser,
page: page,
xvfbsession: xvfbsession,
cdpSession: cdpSession,
chrome: chrome,
setTarget: setTarget
})
})
}
Well i edited it like this, but ads are still there, (the addblock added here part)
It would be helpful if u could guide me through
from puppeteer-real-browser.
I guess its because the page already created, thus the plugin is not registered properly on that initial page you can try add
adblocker.onPageCreated(page)
aftervar page = page[0]
you can also check my fork: https://github.com/eindrawan/puppeteer-real-browser/blob/main/src/index.js
@zfcsoftware may I create a PR for this?
Hi, thanks for your support. I think some plugins may get errors when used in this way. I will update Puppeteer to allow the user to submit.
from puppeteer-real-browser.
hey thanks for the replies, i made it work in my on way
i added the following to the index page
export const connect = ({ args = [], headless = 'auto', customConfig = {}, proxy = {}, skipTarget = [], fingerprint = true, turnstile = false, connectOption = {}, tf = true }) => {
return new Promise(async (resolve, reject) => {
global_target_status = tf
const adblocker = AdblockerPlugin({
blockTrackers: true, // default: false
useCache: false,
})
const blocker = await adblocker.getBlocker()
then returned the blocker, and used the plugins manual blocking like this after creating each page
page = await browser.newPage();
setTarget({ status: true });
blocker.enableBlockingInPage(page);
from puppeteer-real-browser.
@sharpanimes Could you please display the full code snippet that you edited?
from puppeteer-real-browser.
@sharpanimes Could you please display the full code snippet that you edited?
Hey, sorry if my instructions were unclear.
Step-1:The first thing you need is to install the https://www.npmjs.com/package/puppeteer-extra-plugin-adblocker plugin.
Step-2:After that you need to modify the puppeter-real-browser's index page.
I will link the modified index.js page https://pastebin.com/CKvFwAjU
Step-3:- Now in your main project file where you are using puppeter do the following
const response = await connect({
headless: 'auto',
args: [],
customConfig: {},
skipTarget: [],
fingerprint: true,
turnstile: true,
tf: false
});
const { browser, page, setTarget, blocker } = response;
Now whenever you are creating a page do it like below
page = await browser.newPage();
setTarget({ status: true });
blocker.enableBlockingInPage(page);
Now your adblocker should be working
Be sure to import adblocker in you project also to be on the safer side
from puppeteer-real-browser.
@sharpanimes I followed your instructions and encountered an error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\laragon\www\node_modules\puppeteer-real-browser\src\module\afp.js' imported from D:\laragon\www\node_modules\puppeteer-real-browser\src\index.js
from puppeteer-real-browser.
@sharpanimes I followed your instructions and encountered an error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\laragon\www\node_modules\puppeteer-real-browser\src\module\afp.js' imported from D:\laragon\www\node_modules\puppeteer-real-browser\src\index.js
I think there are some changes in the latest version.
I am using version ^1.2.11 . So try installing this version of puppeteer-real-browser
from puppeteer-real-browser.
@sharpanimes I followed your instructions and encountered an error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\laragon\www\node_modules\puppeteer-real-browser\src\module\afp.js' imported from D:\laragon\www\node_modules\puppeteer-real-browser\src\index.js
I think there are some changes in the latest version. I am using version ^1.2.11 . So try installing this version of puppeteer-real-browser
Thank bro
from puppeteer-real-browser.
@sharpanimes I followed your instructions and encountered an error: Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\laragon\www\node_modules\puppeteer-real-browser\src\module\afp.js' imported from D:\laragon\www\node_modules\puppeteer-real-browser\src\index.js
I think there are some changes in the latest version. I am using version ^1.2.11 . So try installing this version of puppeteer-real-browser
@zfcsoftware @sharpanimes According to @sharpanimes, it works well on version 1.2.11 but doesn't work on 1.2.20. Please fix the issue for the puppeteer-real-browser version: '1.2.20'. I tried but couldn't resolve it with the new version.
from puppeteer-real-browser.
@zfcsoftware I see there are many requests for an ad-blocking feature when opening the browser. Please prioritize implementing it! Thank you very much for this useful and wonderful source code.
I will add support in a few days.
Please update . Thanks
from puppeteer-real-browser.
Related Issues (20)
- Error verison 1.2.31 in Ubuntu HOT 3
- Extension Function HOT 2
- Update Feature HOT 3
- Turnstile fails on Windows 11
- Is it possible to solve this captcha? HOT 2
- No longer able to pass turnstile with forced-open shadow root HOT 6
- Ads blocking in puppeteer-real-browser HOT 1
- Extracting tar content of undefined failed, the file appears to be corrupt
- Open modal/sidebar in dextools.io close unexpected
- Not working with custom fingerprint
- Typescript merge into main HOT 1
- Not able to capture screenshots. HOT 1
- Always error with 'Timed out after waiting 30000ms' and other issues HOT 2
- puppeteer-real-browser anti-bot system detect the browser HOT 5
- Hi, why everyone is using Puppeteer but not Playwright HOT 1
- .
- Cloudflare has caught up with PRB again HOT 3
- Proxy Detection HOT 2
- TimeoutError ChromeLauncher.launch HOT 1
- WAF Stopped Working HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from puppeteer-real-browser.