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

Using Google Chrome personal profile as user-data-dir option for chromedp #257

Open
j1cs opened this issue Oct 24, 2024 · 2 comments
Open

Comments

@j1cs
Copy link

j1cs commented Oct 24, 2024

Is your feature request related to a problem? Please describe.
I wonder if is possible to use my personal data dir. Os i can use my sessions to take screenshots from pages that required login using the gowitness api /submit/single

Describe the solution you'd like
I don't know if using wss option using gowitness report server --host=0.0.0.0 --chrome-wss-url=172.17.0.1:9222 can be used

Describe alternatives you've considered
maybe directly passing the path of the data dir like: ~/.config/google-chrome

@j1cs j1cs changed the title Using Google Chrome persona profile as user-data-dir option for chromedp Using Google Chrome personal profile as user-data-dir option for chromedp Oct 24, 2024
@j1cs j1cs closed this as completed Oct 29, 2024
@j1cs j1cs closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@leonjza
Copy link
Member

leonjza commented Oct 29, 2024

Going to re-open this one as a reminder to add a flag where you can specify a user data directory to use.

@leonjza leonjza reopened this Oct 29, 2024
@j1cs
Copy link
Author

j1cs commented Oct 30, 2024

This is how i achieved:

func (m *Media) GetScreenshot(sourceURL string, delay int) (string, string, error) {
	opts := append(chromedp.DefaultExecAllocatorOptions[:],
		chromedp.WindowSize(800, 1024),
		chromedp.UserDataDir(""),
		chromedp.Headless,
	)

	allocCtx, cancelAlloc := chromedp.NewExecAllocator(m.ctx, opts...)
	defer cancelAlloc()

	ctx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(m.log.Info().Msgf), chromedp.WithErrorf(m.log.Error().Msgf))
	defer cancel()

	var screenshotBuffer []byte
	var title string
	err := chromedp.Run(ctx,
		chromedp.Navigate(sourceURL),
		chromedp.Sleep(time.Duration(delay)*time.Second),
		chromedp.CaptureScreenshot(&screenshotBuffer),
		chromedp.Title(&title),
	)
	if err != nil {
		return "", "", fmt.Errorf("failed to capture screenshot: %w", err)
	}

	pathMedia := fmt.Sprintf("%s.jpeg", util.PathMedia())
	err = os.WriteFile(pathMedia, screenshotBuffer, 0644)
	if err != nil {
		return "", "", fmt.Errorf("failed to write screenshot to file: %w", err)
	}

	return pathMedia, title, nil
}

Using the Default profile.

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

2 participants