diff --git a/wp-includes/components/class-wp-service-worker-configuration-component.php b/wp-includes/components/class-wp-service-worker-configuration-component.php index 16c1dc81e..c3c04e8ef 100644 --- a/wp-includes/components/class-wp-service-worker-configuration-component.php +++ b/wp-includes/components/class-wp-service-worker-configuration-component.php @@ -54,6 +54,11 @@ public function get_script() { $current_scope = wp_service_workers()->get_current_scope(); $workbox_dir = sprintf( 'wp-includes/js/workbox-v%s/', PWA_WORKBOX_VERSION ); + $workbox_dir_url = plugins_url( + $workbox_dir, + PWA_PLUGIN_FILE + ); + $script = ''; if ( SCRIPT_DEBUG ) { $enable_debug_log = defined( 'WP_SERVICE_WORKER_DEBUG_LOG' ) && WP_SERVICE_WORKER_DEBUG_LOG; @@ -64,7 +69,7 @@ public function get_script() { // Load with importScripts() so that source map is available. $script .= sprintf( "importScripts( %s );\n", - wp_json_encode( PWA_PLUGIN_URL . $workbox_dir . 'workbox-sw.js' ) + wp_json_encode( $workbox_dir_url . 'workbox-sw.js' ) ); } else { // Inline the workbox-sw.js to avoid an additional HTTP request. @@ -74,7 +79,7 @@ public function get_script() { $options = array( 'debug' => SCRIPT_DEBUG, // When true, the dev builds are loaded. Otherwise, the prod builds are used. - 'modulePathPrefix' => PWA_PLUGIN_URL . $workbox_dir, + 'modulePathPrefix' => $workbox_dir_url, ); $script .= sprintf( "workbox.setConfig( %s );\n", wp_json_encode( $options ) ); diff --git a/wp-includes/service-workers.php b/wp-includes/service-workers.php index 31a53ff76..04d4dddfb 100644 --- a/wp-includes/service-workers.php +++ b/wp-includes/service-workers.php @@ -167,11 +167,13 @@ function wp_print_service_workers() { return; } - $workbox_window_src = sprintf( - '%s/wp-includes/js/workbox-v%s/workbox-window.%s.js', - PWA_PLUGIN_URL, - PWA_WORKBOX_VERSION, - SCRIPT_DEBUG ? 'dev' : 'prod' + $workbox_window_src = plugins_url( + sprintf( + 'wp-includes/js/workbox-v%s/workbox-window.%s.js', + PWA_WORKBOX_VERSION, + SCRIPT_DEBUG ? 'dev' : 'prod' + ), + PWA_PLUGIN_FILE ); $register_options = array( 'scope' => $scope,