Skip to content
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

Is it possible to capture error messages related to CORS, CSP violations, mixed-content violations, etc.? #1463

Open
jub0bs opened this issue Apr 4, 2024 · 0 comments

Comments

@jub0bs
Copy link

jub0bs commented Apr 4, 2024

What versions are you running?

$ go list -m github.com/chromedp/chromedp
github.com/chromedp/chromedp v0.9.5
$ chromium --version
Chromium 125.0.6399.0
$ go version
go version go1.22.1 darwin/amd64

What did you do? Include clear steps.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/chromedp/cdproto/runtime"
	"github.com/chromedp/chromedp"
)

const (
	url            = "https://example.com/"
	crossOriginURL = "https://www.example.com/robots.txt"
)

func main() {
	ctx, cancel := chromedp.NewContext(context.Background())
	defer cancel()

	chromedp.ListenTarget(ctx, func(ev interface{}) {
		switch ev := ev.(type) {
		case *runtime.EventExceptionThrown:
			fmt.Println(ev.ExceptionDetails.Error())
		}
	})

	err := chromedp.Run(ctx,
		chromedp.Navigate(url),
		chromedp.Evaluate(`fetch("`+crossOriginURL+`")`, nil),
	)
	if err != nil {
		log.Fatal(err)
	}
}

What did you expect to see?

I expected the output to contain the following CORS error message:

Access to fetch at 'https://www.example.com/robots.txt' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

What did you see instead?

Nothing.

@jub0bs jub0bs changed the title Is it possible to capture CORS error messages? Is it possible to capture error messages related to CORS, CSP violations, mixed-content violations, etc.? Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant