Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64732

QWebEngineCookieStore::setCookie will change the cookie domain by adding a leading dot

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.10.1
    • 5.9.2
    • WebEngine
    • None
    • os: mac 10.12.6

      qt: 5.9.2

    Description

      QList<QNetworkCookie> cookies;
      
      QObject::connect(Browser->page()->profile()->cookieStore(), &QWebEngineCookieStore::cookieAdded, [this](const QNetworkCookie &cookie) {
          cookies.append(cookie);
          qDebug() << "Cookie Added -" << cookie.domain() << cookie.name() << endl;
      });
      
      // First visit, the cookies was saved correctly (the server sent any cookies with domain - aa.bb.cc.com).
      Browser->load(QUrl("https://aa.bb.cc.com"));
      
      // Next time to re-visit it with the saved cookies
      Browser->page()->profile()->cookieStore()->deleteAllCookies();
      for (auto cookie : cookies) {
          Browser->page()->profile()->cookieStore()->setCookie(cookie);
          or
          Browser->page()->profile()->cookieStore()->setCookie(cookie, QUrl("https://aa.bb.cc.com"));
          qDebug() << "[account] set>>" << cookie.domain() << cookie.name() << endl;
      }
      Browser->load(QUrl("https://aa.bb.cc.com"));
      // the cookie domain has been changed by QWebEngineCookieStore::setCookie, it will automatically add a leading dot to the domain
      
      Result:
      // first visit
      Cookie Added - "aa.bb.cc.com" "uuid"
      
      // second visit
      [account] set>> "aa.bb.cc.com" "uuid"
      Cookie Added - ".aa.bb.cc.com" "uuid"
      
      
      

      Attachments

        1. cookie.png
          cookie.png
          96 kB
        2. main.cpp
          2 kB
        3. webengine_cookies_dot.pro
          0.1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            michal Michal Klocek
            wukong Justin Wu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes