Skip to content

[Bug]: TargetClosedError when calling path() on Download after page.waitForDownload() #1952

Description

@sascha-luck

Version

1.61.0

Steps to reproduce

after switching to Version 1.61.0 (from 1.57.0) I get following error: com.microsoft.playwright.impl.TargetClosedError: Target page, context or browser has been closed

the code snippet is:

		Download download = page.waitForDownload(new Page.WaitForDownloadOptions().setTimeout(120_000), () -> locator.first().click(new Locator.ClickOptions().setTimeout(120_000)));
		final List<String> stringList;
		try (InputStream inputStream = download.createReadStream()) {
			// do something with the inputStream
		} catch (IOException e) {
			throw new PlaywrightException("error processing downloaded pdf",e);
		}

Expected behavior

I expect that after downloading i can access the downloaded file to do the needed checks

Actual behavior

com.microsoft.playwright.impl.TargetClosedError: Target page, context or browser has been closed

	at com.microsoft.playwright.impl.PageImpl$WaitablePageClose.get(PageImpl.java:1516)
	at com.microsoft.playwright.impl.WaitableRace.get(WaitableRace.java:46)
	at com.microsoft.playwright.impl.WaitableRace.get(WaitableRace.java:46)
	at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:146)
	at com.microsoft.playwright.impl.FrameImpl.waitForLoadStateImpl(FrameImpl.java:848)
	at com.microsoft.playwright.impl.FrameImpl.waitForLoadStateImpl(FrameImpl.java:833)
	at com.microsoft.playwright.impl.PageImpl.lambda$waitForLoadState$14(PageImpl.java:1462)
	at com.microsoft.playwright.impl.WaitForEventLogger.get(WaitForEventLogger.java:50)
	at com.microsoft.playwright.impl.ChannelOwner.withWaitLogging(ChannelOwner.java:84)
	at com.microsoft.playwright.impl.PageImpl.lambda$waitForLoadState$15(PageImpl.java:1461)
	at com.microsoft.playwright.impl.ChannelOwner.lambda$withTitle$0(ChannelOwner.java:90)
	at com.microsoft.playwright.impl.ChannelOwner.withTitle(ChannelOwner.java:98)
	at com.microsoft.playwright.impl.ChannelOwner.withTitle(ChannelOwner.java:89)
	at com.microsoft.playwright.impl.PageImpl.waitForLoadState(PageImpl.java:1460)
	at com.microsoft.playwright.Page.waitForLoadState(Page.java:7998)
	at com.microsoft.playwright.Page.waitForLoadState(Page.java:8026)
	at com.microsoft.playwright.impl.ListenerCollection.notify(ListenerCollection.java:45)
	at com.microsoft.playwright.impl.BrowserContextImpl.handleEvent(BrowserContextImpl.java:789)
	at com.microsoft.playwright.impl.Connection.dispatch(Connection.java:307)
	at com.microsoft.playwright.impl.Connection.processOneMessage(Connection.java:222)
	at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:144)
	at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:132)
	at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:132)
	at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:122)
	at com.microsoft.playwright.impl.ArtifactImpl.pathAfterFinished(ArtifactImpl.java:75)
	at com.microsoft.playwright.impl.DownloadImpl.path(DownloadImpl.java:74)

Additional context

No response

Environment

  • Browser: Firefox
  • Java Version: [21]
  • Maven Version: [3.9.6]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions