PWABuilder icon indicating copy to clipboard operation
PWABuilder copied to clipboard

PWAs with search parameters in their URLs (?parameter1=value) do not work

Open davidpolberger opened this issue 6 years ago • 9 comments

Describe the bug A PWA whose manifest URL includes search parameters does not work.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://www.pwabuilder.com
  2. Enter a PWA URL, whose manifest URL includes search parameters, into the #getstartedinput element. Here's a sample URL.
  3. Click the #getstartedbutton element.

Expected behavior The manifest should be found.

Additional info (please complete the following information):

  • OS: Fedora
  • Browser: Firefox
  • Browser Version: 78

Additional context This bug is present in pwabuilder-lib. Specifically, manifestLoader.js contains a bug in fetchManifestUrlFromSite(). It correctly extracts the manifest URL using the Cheerio library and parses it using the URL class. It then resolves the path name of the URL against the URL of the site ("siteUrl"), but disregards the search parameters:

function fetchManifestUrlFromSite (siteUrl, callback) {
  var deferred = Q.defer();
  request({ uri: siteUrl }, function (err, response, body) {
    if (err || response.statusCode !== 200) {
      return deferred.reject(new Error('Failed to retrieve manifest from site.'));
    }

    var $ = cheerio.load(body);
    var manifestUrl = $('link[rel~="manifest"]').attr('href');
    if (manifestUrl) {
      var parsedManifestUrl = url.parse(manifestUrl);
      if (!parsedManifestUrl.host) {
        // The bug is on the line below:
        manifestUrl = url.resolve(siteUrl, parsedManifestUrl.pathname);
      }
    }

    return deferred.resolve(manifestUrl);
  });

  return deferred.promise.nodeify(callback);
}

Fixing this is as simple as concatenating the pathname property of the URL object with the search property of the same object:

function fetchManifestUrlFromSite (siteUrl, callback) {
  var deferred = Q.defer();
  request({ uri: siteUrl }, function (err, response, body) {
    if (err || response.statusCode !== 200) {
      return deferred.reject(new Error('Failed to retrieve manifest from site.'));
    }

    var $ = cheerio.load(body);
    var manifestUrl = $('link[rel~="manifest"]').attr('href');
    if (manifestUrl) {
      var parsedManifestUrl = url.parse(manifestUrl);
      if (!parsedManifestUrl.host) {
        // The fix is on the line below:
        manifestUrl = url.resolve(siteUrl,
                                  parsedManifestUrl.pathname +
                                  parsedManifestUrl.search);
      }
    }

    return deferred.resolve(manifestUrl);
  });

  return deferred.promise.nodeify(callback);
}

This fix has been tested against the sample PWA URL listed above and works well.

davidpolberger avatar Jul 11 '20 22:07 davidpolberger

Hello davidpolberger, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will investigate the issue and help solve it ASAP. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Jul 11 '20 22:07 ghost

@lee-leonardo can you have a look at this?

JudahGabriel avatar Jul 15 '20 17:07 JudahGabriel

I've pushed a fix for this here. We should have this fix rolled out to the site soon. I'll update here when it is.

JudahGabriel avatar Jul 21 '20 00:07 JudahGabriel

Could we have an update on when this will be pushed live to the site? We'd love to promote this to our customers if the service works well with the PWAs produced by Calcapp.

davidpolberger avatar Aug 15 '20 17:08 davidpolberger

This update has been deployed - but I still see your PWA manifest not being detected. Reopening this case.

JudahGabriel avatar Aug 26 '20 17:08 JudahGabriel

This has been fixed with this PR. It's deployed to preview.pwabuilder.com, and we will roll out to production within the next week.

JudahGabriel avatar Sep 17 '20 19:09 JudahGabriel

That's excellent news, thank you so much!

davidpolberger avatar Sep 17 '20 21:09 davidpolberger

I get a score of 100 now with this URL and I can successfully build apps for Windows and Android. However, I cannot build macOS or Samsung apps. I filed this issue to track that bug.

davidpolberger avatar Sep 17 '20 22:09 davidpolberger

Glad it's fixed this issue. For your MacOS build issue, I'll comment there.

JudahGabriel avatar Sep 17 '20 22:09 JudahGabriel