Skip to content

Commit

Permalink
fix: Include third-party cookies when fetching images (#182)
Browse files Browse the repository at this point in the history
* fix: include third-party cookies when fetching images

* fix: set src property on Image instance

* test: verify that img.src is set
  • Loading branch information
slawekkolodziej committed May 24, 2022
1 parent e6260a0 commit 90c43a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/web-worker/worker-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export const createImageConstructor = (env: WebWorkerEnvironment) =>
logWorker(`Image() request: ${resolveUrl(env, src)}`, env.$winId$);
}

this.s = src;

fetch(resolveUrl(env, src, true), {
mode: 'no-cors',
credentials: 'include',
keepalive: true,
}).then(
(rsp) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/platform/image/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ test('image', async ({ page }) => {
await page.waitForSelector('.testImgListenerError');
const testImgListenerError = page.locator('#testImgListenerError');
await expect(testImgListenerError).toHaveText('error');

await page.waitForSelector('.testImgSrc');
const testImgSrc = page.locator('#testImgSrc');
await expect(testImgSrc).toHaveText('dot.gif?imageSrcTest');
});
16 changes: 16 additions & 0 deletions tests/platform/image/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ <h1>Image</h1>
})();
</script>
</li>

<li>
<strong>&lt;img&gt; src</strong>
<code id="testImgSrc"></code>
<script type="text/partytown">
(function () {
const image = new Image();
image.src = 'dot.gif?imageSrcTest';
image.onload = function (ev) {
const elm = document.getElementById('testImgSrc');
elm.textContent = image.src;
elm.className = 'testImgSrc';
};
})();
</script>
</li>
</ul>

<hr />
Expand Down

1 comment on commit 90c43a2

@vercel
Copy link

@vercel vercel bot commented on 90c43a2 May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.