New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bypass headless chrome detection #396
Comments
It seems to me like this is more about how you can get the equivalent of If you have any insight into that, or know how this could be done with the devtools protocol, any help is appreciated. |
Yes, you are absolutely right,
/**
* @param {Function|string} pageFunction
* @param {!Array<*>} args
*/
async evaluateOnNewDocument(pageFunction, ...args) {
const source = helper.evaluationString(pageFunction, ...args);
await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source });
} |
chromedp.ActionFunc(func(ctx context.Context) error {
identifier, err := page.AddScriptToEvaluateOnNewDocument(`Object.defineProperty(navigator, 'plugins', {get: () => [1, 2, 3, 4, 5, 7, 8, 9]});`).Do(ctx)
if err != nil {
return err
}
fmt.Println("identifier: ", identifier.String())
return nil
}),
|
I was just about to point out the |
BTW -- I will post code later to pass this test. It's just a matter of setting up the JavaScript. Please note, that the |
package main
import (
"context"
"io/ioutil"
"log"
"github.com/chromedp/cdproto/page"
"github.com/chromedp/chromedp"
)
func main() {
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithDebugf(log.Printf))
defer cancel()
// see: https://intoli.com/blog/not-possible-to-block-chrome-headless/
const script = `(function(w, n, wn) {
// Pass the Webdriver Test.
Object.defineProperty(n, 'webdriver', {
get: () => false,
});
// Pass the Plugins Length Test.
// Overwrite the plugins property to use a custom getter.
Object.defineProperty(n, 'plugins', {
// This just needs to have length > 0 for the current test,
// but we could mock the plugins too if necessary.
get: () => [1, 2, 3, 4, 5],
});
// Pass the Languages Test.
// Overwrite the plugins property to use a custom getter.
Object.defineProperty(n, 'languages', {
get: () => ['en-US', 'en'],
});
// Pass the Chrome Test.
// We can mock this in as much depth as we need for the test.
w.chrome = {
runtime: {},
};
// Pass the Permissions Test.
const originalQuery = wn.permissions.query;
return wn.permissions.query = (parameters) => (
parameters.name === 'notifications' ?
Promise.resolve({ state: Notification.permission }) :
originalQuery(parameters)
);
})(window, navigator, window.navigator);`
var buf []byte
var scriptID page.ScriptIdentifier
if err := chromedp.Run(
ctx,
//chromedp.Emulate(device.IPhone7),
chromedp.ActionFunc(func(ctx context.Context) error {
var err error
scriptID, err = page.AddScriptToEvaluateOnNewDocument(script).Do(ctx)
if err != nil {
return err
}
return nil
}),
chromedp.Navigate("https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html"),
chromedp.CaptureScreenshot(&buf),
); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("screenshot.png", buf, 0644); err != nil {
log.Fatal(err)
}
} It also works with emulating other devices, such as an IPhone7. See the attached screenshot: Note: I'm using the |
Hi, you can get the link here https://intoli.com/blog/not-possible-to-block-chrome-headless/ or direct link https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html. 01.07.2020, 10:27, "n3ver" <notifications@github.com>: See the attached screenshot:Hi, May I ask where I can get the attached screenshot?—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
|
thx, that helps a lot!
Evgeny Panov <notifications@github.com> 于 2020年7月1日周三 下午11:15写道:
… Hi, you can get the link here
https://intoli.com/blog/not-possible-to-block-chrome-headless/ or direct
link
https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html. 01.07.2020,
10:27, "n3ver" ***@***.***>: See the attached
screenshot:Hi, May I ask where I can get the attached screenshot?—You are
receiving this because you authored the thread.Reply to this email
directly, view it on GitHub, or unsubscribe.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#396 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC25UARWWXLFV3CNCSJDWULRZNHJ3ANCNFSM4HZDXDJQ>
.
|
Is that possible to send |
Trying to get through the Cloudflare for downloading this file: My test results are:
Tried with Has anyone been able to work around the Cloudflare protection? P.S. I'm using slightly modified example: |
@rusq Your issue is not the same as the one discussed here. In your case, there is not js code running in the browser to detect the headless mode. The detection happens on the server side. What you should do is to provide a customized update: Sorry, I just realized #807 is created by you. |
Hey @ZekeLu your help is invaluable, thank you again!
I modified the options to include the user agent and it worked like a charm! opts := [...]func(*chromedp.ExecAllocator){
chromedp.NoFirstRun,
chromedp.NoDefaultBrowserCheck,
chromedp.Headless,
chromedp.UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"),
} |
Hey @ZekeLu I have combined the solutions above that got the download going into a small library draft: https://github.com/rusq/chromedl Going to test it on production soon (best way to test things, current http.Get() doesn't work anyway) |
Better to create allocator options like this: opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"),
) |
I can not get content for this (warning!) malicious link I tried to modify the user-agent
I have the same problem with https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.js My code
|
Here is another malicious URL P.S. The page returns 404 now |
Sorry to revive this closed issue, but I'm trying to screenshot this website: https://www.royalnavy.mod.uk/qhm/portsmouth/shipping-movements and even following the techniques discussed in this thread it just comes out as a blank white screenshot - other cloudflare protected sites work, just not this one for some reason. I am changing the useragent to one I know works (tested with puppeteer) and running the script that passes the intoli.com test. Any ideas anyone? |
Yep as I said I tried the fixes suggested such as changing the useragent and inserting the script, I still just get a blank white screen |
It works on my computer. And maybe it's a screenshot issue, see #863. If it still does not work on your computer, see the comment in the source code for how to debug the issue. package main
import (
"context"
"io/ioutil"
"log"
"github.com/chromedp/chromedp"
)
func main() {
opts := append(chromedp.DefaultExecAllocatorOptions[:],
// set up a proxy (such as Fiddler) and uncomment the next two lines to see the network requests if it still does not work.
//chromedp.ProxyServer("localhost:8866"),
//chromedp.Flag("ignore-certificate-errors", true),
chromedp.UserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36"),
)
ctx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
ctx, cancel = chromedp.NewContext(
ctx,
// uncomment the next line to see the CDP messages
//chromedp.WithDebugf(log.Printf),
)
defer cancel()
var buf []byte
err := chromedp.Run(ctx,
chromedp.Navigate(`https://www.royalnavy.mod.uk/qhm/portsmouth/shipping-movements`),
chromedp.CaptureScreenshot(&buf),
)
if err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("screenshot.png", buf, 0o644); err != nil {
log.Fatal(err)
}
} |
OK interesting, thanks |
Thank you! It works for me. |
Regarding this issue; I was also running into some issues and created this lib to fix it; undetected-chromedp |
What versions are you running?
What did you do? Include clear steps.
What did you expect to see?
I am trying to bypass headless browser detection as written in this article https://intoli.com/blog/not-possible-to-block-chrome-headless/. This works fine for puppeteer, but doesn't work for chromedp. I need to understand how to execute js code in chromedp, as in puppeteer. Because every time after run chromedp.Navigate() values are reset to default.
It is possible to do with chromedp?
What did you see instead?
Works fine with puppeteer.
The text was updated successfully, but these errors were encountered: