8000 fix: Replaced classLoader in DriverJar by ArcticFoox · Pull Request #1811 · microsoft/playwright-java · GitHub
[go: up one dir, main page]

Skip to content

fix: Replaced classLoader in DriverJar #1811

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArcticFoox
Copy link
@ArcticFoox ArcticFoox commented Jun 24, 2025

@yury-s
In some environments, such as Docker or the sbt plugin, accessing the ContextClassLoader is not reliable.
Because the driver package is bundled within the JAR, class.getClassLoader() is used instead.

issues: #1447 , #1803

@ArcticFoox ArcticFoox marked this pull request as draft June 24, 2025 12:59
@ArcticFoox ArcticFoox marked this pull request as ready for review June 24, 2025 13:01
@yury-s
Copy link
Member
yury-s commented Jun 24, 2025

Since we could not reproduce it before, can you add a test that demonstrates the bug and that the fix actually resolves it?

@ArcticFoox
Copy link
Author
ArcticFoox commented Jun 24, 2025

Ok, I will try it

@ArcticFoox
Copy link
Author
ArcticFoox commented Jun 27, 2025

Hi, @yury-s
In our internal project, we use Playwright to take a screenshot asynchronously using CompletableFuture when Open Graph tags are not found on a given page. This setup works fine locally.

However, when running the same code inside a Docker container, the following issue occurs:

Thread.currentThread().getContextClassLoader() returns null
This causes failures when attempting to load resources (e.g., getResource(...)).

After investigation, I found that switching to:

this.getClass().getClassLoader()
resolves the issue both locally and in the Docker container.

To help reproduce and compare the issue, I’ve created a sample repo here:
👉 https://github.com/ArcticFoox/driverJar-test

You can build the Docker image using the included Dockerfile and test the endpoints:

http://localhost:8080/playwright?url=https://google.com (uses Thread.currentThread().getContextClassLoader())

-> You can check the error log in the console when accessing this endpoint.

http://localhost:8080/playwright2?url=https://google.com (uses this.getClass().getClassLoader())

This is my first open source contribution, so I’d appreciate any feedback or suggestions!

Thank you 🙇

@yury-s
Copy link
Member
yury-s commented Jun 30, 2025

The test has quite some logic which make it not obvious wether the problem is in the test or in Playwright. Can you try to reduce it to a minimal example and drop all unrelated logic? Ideally it would be converted into one of the Playwright tests.

If the setup requires a custom environment (e.g. spring framework), you can put it in its own project. There is already a bunch of custom tests in the tools/ directory, particularly this one. You could convert yours into a similar one.

We also run Docker tests for our container on GitHub Actions: https://github.com/microsoft/playwright-java/actions/workflows/test_docker.yml. If the test requires Docker environment, we can run the new test inside the Playwright Docker image as part of the same test suite. Would that work?

Given that this PR change the core part of the project, I'd really like to have a test that covers it.

@ArcticFoox
Copy link
Author

Sure, I’ll go ahead with that.

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

Successfully merging this pull request may close these issues.

2 participants
0