File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -102,14 +102,18 @@ const utils = {
102102 getCanonicalUrl : ( ) => {
103103 let canonicalURL = null ;
104104
105- if ( utils . canUseDOM ( ) ) {
106- const linkEle = document ?. querySelector ( 'link[rel="canonical"]' ) ;
107- const href = linkEle ?. getAttribute ( 'href' ) ;
105+ try {
106+ if ( utils . canUseDOM ( ) ) {
107+ const linkEle = document ?. querySelector ( 'link[rel="canonical"]' ) ;
108+ const href = linkEle ?. getAttribute ( 'href' ) ;
108109
109- if ( href ) {
110- const url = new URL ( href , document . location . href ) ;
111- canonicalURL = url . toString ( ) ;
110+ if ( href ) {
111+ const url = new URL ( href , document . location . href ) ;
112+ canonicalURL = url . toString ( ) ;
113+ }
112114 }
115+ } catch ( e ) {
116+ // do nothing
113117 }
114118
115119 return canonicalURL ;
You can’t perform that action at this time.
0 commit comments