JavaScript de URL dividido

const url = 'http://www.mymainsite.com/somepath/path2/path3/path4';
const pathname = new URL(url).pathname;
console.log(pathname);
Undefined