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

Wrong window.location after redirection #1627

Closed
spamshaker opened this issue Nov 26, 2024 · 1 comment · Fixed by #1651
Closed

Wrong window.location after redirection #1627

spamshaker opened this issue Nov 26, 2024 · 1 comment · Fixed by #1651
Assignees
Labels
bug Something isn't working

Comments

@spamshaker
Copy link

spamshaker commented Nov 26, 2024

Describe the bug
When you want to access the final location after redirection the location is set to initial while browser exposes the final location.

To Reproduce

npm i msw happy-dom
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { deepEqual, strictEqual } from 'node:assert';
import { Browser } from 'happy-dom';

const handlers = [
  http.get('https://example.com/user', () => {
    return HttpResponse.redirect('https://example.com/auth');
  }),
  http.get('https://example.com/auth', () => {
    return HttpResponse.html('AUTH PAGE');
  }),
  http.get('*', (req) => {
    throw new Error('Not mocked yet' + req.request.url);
  })
];
const server = setupServer(...handlers);
server.listen();
const result = await fetch('https://example.com/user').then(async (res) => {
  return {
    status: res.status,
    content: res.headers.get('content-type')?.includes('json') ? await res.json() : await res.text()
  };
});

// Ensure MSW redirected content properly while fetch
deepEqual(result, { status: 200, content: 'AUTH PAGE' });

const browser = new Browser();
const page = browser.newPage();
await page.goto('https://example.com/user');
strictEqual(page.content, '<html><head></head><body>AUTH PAGE</body></html>');
strictEqual(page.mainFrame.window.location.href, 'https://example.com/auth');
//  ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
// + actual - expected

// + 'https://example.com/user'
// - 'https://example.com/auth'

Expected behavior
this should pass

strictEqual(page.mainFrame.window.location.href, 'https://example.com/auth');

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: MacOs
  • Browser: nodejs
  • Version: 22

Additional context

@spamshaker spamshaker added the bug Something isn't working label Nov 26, 2024
@spamshaker spamshaker changed the title Wrong window.location after redirect Wrong window.location after redirection Nov 26, 2024
@capricorn86 capricorn86 self-assigned this Dec 30, 2024
capricorn86 added a commit that referenced this issue Dec 30, 2024
…direct in BrowserFrame.goto and DetachedBrowserFrame.goto
capricorn86 added a commit that referenced this issue Dec 30, 2024
…direct in BrowserFrame.goto and DetachedBrowserFrame.goto (#1651)
@capricorn86
Copy link
Owner

Thank you for reporting @spamshaker! 🙂

This should be fixed now in v16.2.4

capricorn86 added a commit that referenced this issue Dec 31, 2024
…lement remove, replaceWith, before, after, append, prepend, replaceChildren and insertAdjacentElement
capricorn86 added a commit that referenced this issue Dec 31, 2024
…lement remove, replaceWith, before, after, append, prepend, replaceChildren and insertAdjacentElement
capricorn86 added a commit that referenced this issue Dec 31, 2024
…lement remove, replaceWith, before, after, append, prepend, replaceChildren and insertAdjacentElement (#1652)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants