UrlObject: {
    url: string;
} | {
    href: string;
}

The UrlObject type is used for passing URL parameters into some methods. It can be either an object with a url property, or an object with an href property.

  • If the object has a url property, the value of that property is used as the URL.
  • If the object has an href property, the that string is first processed to replace all + with %20 and then used as the URL.
  • If the object has both url and href properties, the url property is used.

The rationale for this is that URL objects in JavaScript provide the href property, with spaces encoded as +. Most modern APIs expect spaces to be encoded as %20, so this behaviour allows URL objects to be passed in to methods that want a url, without needing to manually re-encode spaces.

Type declaration

  • url: string

    String to be used as-is.

Type declaration

  • href: string

    String in which PopClip will replace + characters with %20 before use.

Example

const exampleUrl=new URL("https://example.com/path");
exampleUrl.searchParams.set("q","query with spaces");
print(exampleUrl.href)); // this will print "https://example.com/path?q=query+with+spaces"
popclip.openUrl(exampleUrl); // this will open "https://example.com/path?q=query%20with%20spaces"