diff --git a/code/lib/preview-api/src/modules/preview-web/UrlStore.ts b/code/lib/preview-api/src/modules/preview-web/UrlStore.ts index 16d66ba7f6b6..f69e6b520f96 100644 --- a/code/lib/preview-api/src/modules/preview-web/UrlStore.ts +++ b/code/lib/preview-api/src/modules/preview-web/UrlStore.ts @@ -65,7 +65,7 @@ const getFirstString = (v: ValueOf): string | void => { }; export const getSelectionSpecifierFromPath: () => SelectionSpecifier | null = () => { - const query = qs.parse(document.location.search, { ignoreQueryPrefix: true }); + const query = qs.parse(document?.location?.search, { ignoreQueryPrefix: true }); const args = typeof query.args === 'string' ? parseArgsParam(query.args) : undefined; const globals = typeof query.globals === 'string' ? parseArgsParam(query.globals) : undefined; diff --git a/code/lib/preview-api/src/modules/preview-web/WebView.ts b/code/lib/preview-api/src/modules/preview-web/WebView.ts index 6f02568934c3..eefa4f007856 100644 --- a/code/lib/preview-api/src/modules/preview-web/WebView.ts +++ b/code/lib/preview-api/src/modules/preview-web/WebView.ts @@ -47,7 +47,7 @@ export class WebView implements View { constructor() { // Special code for testing situations // eslint-disable-next-line @typescript-eslint/naming-convention - const { __SPECIAL_TEST_PARAMETER__ } = qs.parse(document.location.search, { + const { __SPECIAL_TEST_PARAMETER__ } = qs.parse(document?.location?.search, { ignoreQueryPrefix: true, }); switch (__SPECIAL_TEST_PARAMETER__) {