The cookie value is blank once after moving to the second page

I'm facing an issue with 2 domains where performing an action on the first domain results in setting a cookie that should be accessible on both domains. However, when trying to read the value of this cookie on the second domain, it appears empty. Can anyone explain why?

Here's a snippet of code that retrieves the cookie value:

const getCookie = ClientFunction(() => {
    const name = 'ConfigCookie';
    const match = document.cookie.match(new RegExp(name + '=([^;]+)'));
    let decodedValue;
    if (match) decodedValue = decodeURIComponent(match[1]).replace(/%28/g, '(').replace(/%29/g, ')');
    return JSON.parse(decodedValue || '');
})

Below is a test script (with sensitive data removed) that replicates the problem:

test('xyz', async t => {
    await t
        .navigateTo(FirstDomain)
        .click(firstDomainSubmitButtonSelector)
        const firstDomainCookie = await getCookie();
        const firstDomainConsents = firstDomainCookie.consents;
    await t
        .expect(consents).eql({here the expected value});
    await t
        .navigateTo(SecondDomain)
        const secondDomainCookie = await getCookie();
        const secondDomainConsents = secondDomainCookie.consents;
        console.log(secondDomainConsents)
})

Answer №1

After creating a code snippet using TestCafe, I was able to successfully demonstrate the behavior as described. The test passed without any issues on my end. However, if you could modify the test to showcase the problematic behavior and then provide me with the corrected code, I would appreciate it so that I can replicate the issue on my side.

import { Selector, ClientFunction } from 'testcafe';
 
fixture`test fixture`
const FirstDomain = 'http://devexpress.github.io/testcafe/example';
const SecondDomain = 'https://wikipedia.org/';
test('test name', async t => {
    const setCookie = ClientFunction(() => {
        document.cookie = 'key=value'
    });
    const getCookie = ClientFunction(() => {
        return document.cookie;
    });
    const data = 'key=value'
    await t.navigateTo(FirstDomain)
    await setCookie()
    await t.expect(await getCookie(data)).ok()
    await t.navigateTo(SecondDomain)
    await setCookie()
    await t.expect(await getCookie()).ok(data)
    await t.navigateTo(FirstDomain).click(await Selector('#submit-button'))
    await t.expect(await getCookie()).ok(data)
    await t.navigateTo(SecondDomain)
    await t.expect(await getCookie()).ok(data)
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using TypeScript and NestJs: Spread types can only be generated from object types

I'm encountering an issue while trying to pass two parameters using the spread operator from the book.controller to the book.service.ts service. The error message I'm receiving is: Spread types may only be created from object types It's w ...

Is it possible to modify the authenticated user ID right before its creation in Firebase, especially when the user is being created via the Facebook provider?

As we transition our MongoDB database to Firebase with Firestore, we are facing the challenge of integrating Firebase authentication for our users. Currently, we store user data in Firestore and want to utilize Firebase authentication for user logins. Each ...

Persisting Undefined Values Even After Proper Prop Passing

I'm currently working on fetching and passing coaching data as props to another component for rendering on the frontend. I need to pass these props to the CoachingCard Component in order to display the coaching values. However, I'm encountering ...

Checking a TypeScript project with various start points for linting

Within my extensive application that is constructed using webpack, there are numerous entry points that are generated dynamically. Each entry point requires specific target files to be created during the build process. I have already realized that when bu ...

How can I arrange a table in Angular by the value of a specific cell?

Here's the current layout of my table: Status Draft Pending Complete I'm looking for a way to sort these rows based on their values. The code snippet I've been using only allows sorting by clicking on the status header: onCh ...

"Encountering Devextreme Reactive Errors while navigating on the main client

Attempting to integrate Devextreme with Material Ui in my Typescript React app has been a challenge. Despite following the steps outlined in this documentation and installing all necessary packages, I am encountering issues. I have also installed Material ...

Is it possible to modify the CSS injected by an Angular Directive?

Is there a way to override the CSS generated by an Angular directive? Take, for instance, when we apply the sort directive to the material data table. This can result in issues like altering the layout of the column header. Attempting to override the CSS ...

Accessing HTTP data through a function instead of using ngOnInit in Angular is a more efficient approach

Trying to retrieve data from a service using setInterval has posed an issue for me. When I call the service from ngOnInit, everything functions as expected. However, when attempting to call it from any other function, an error occurs: "ERROR TypeError: Ca ...

How can I toggle the visibility of a div after the DOM has finished loading?

I was experimenting with a radio button on the interface linked to a property in the typescript file that controls the visibility of another div. However, I noticed that both *ngIf="isFooSelected" and [hidden]="!isFooSelected" only function upon initial pa ...

Utilizing 'nestjs/jwt' for generating tokens with a unique secret tailored to each individual user

I'm currently in the process of generating a user token based on the user's secret during login. However, instead of utilizing a secret from the environment variables, my goal is to use a secret that is associated with a user object stored within ...

The parameter type cannot be assigned to an array type of 'IAulasAdicionais[]'

I am facing a problem in my application that I need help solving. The issue lies within my code, and I have included some prints of the error below: Mock data: "AulasAdicionais": [ { "Periodo": "1", "Hora ...

Dynamically load components within a modal window

I am looking for a way to dynamically load a custom component inside a modal while keeping it as flexible as possible. Here is an example : -HTML CODE- <button id="floating_button" class="floating_button animation_floating_in" (click)="loadCustomComp ...

Absence of "Go to Definition" option in the VSCode menu

I'm currently working on a Typescript/Javascript project in VSCODE. Previously, I could hover my mouse over a method to see its function definition and use `cmd + click` to go to the definition. However, for some unknown reason, the "Go to Definition" ...

The Next.js website displays a favicon in Chrome, but it does not appear in Brave browser

As I work on my debut next.js website, I am configuring the favicon in index.js like this: <Head> <title>Create Next App</title> <link rel="icon" href="/favicon.ico" /> </Head> Initially, all my source ...

The function userRole consistently returns "user" regardless of the role being admin

I am facing an issue with the getTeamMembers() method while trying to identify which members are admins in a private team. Even though I am logged in as an admin, the userRole value always shows as "user". Can anyone assist me with this problem? import { ...

Preventing driver closure during test suites in Appium/Webdriverio: a step-by-step guide

Currently, I am in the process of testing a react native application with a specific test suite and test cases. The test case files I am working with are: login.ts doActionAfterLogin_A.ts Test Suite: [login.ts, doActionAfterLogin_A.ts] Issue at Hand: W ...

Prevent Cookie Access from AJAX REST Request in JavaScript

We are in the process of developing a mobile application using web technology. Our endpoint (weblogic 11g) sends both a jessionid cookie and a _wl_authcookie_jessionid_ cookie which are automatically sent back to the server for authentication purposes. How ...

Typescript not flagging an error for an object being declared without a type

I am encountering an issue with my tsconfig.json file: { "compilerOptions": { "allowJs": true, "allowSyntheticDefaultImports": true, "baseUrl": "src", "isolatedModules": true, "jsx": "preserve", "esModuleInterop": true, "forc ...

What strategies can I employ to help JSDoc/TypeScript recognize JavaScript imports?

After adding // @ts-check to my JavaScript file for JSDoc usage, I encountered errors in VS Code related to functions included with a script tag: <script src="imported-file.js"></script> To suppress these errors, I resorted to using ...

Using Angular 2, you can pass an object as a parameter to a function

Is there a way to pass an object as a parameter in the DOM on this forum? Within my HTML code, I have the following: <div class="list-items"> <ul> <li *ngFor="let i of item"> <span (click)="onAdd({{newUser.us ...