当使用 Playwright 启动时,竞争条件导致资产从 Electron 中的错误位置加载
我有一个电子应用程序,我正在尝试将剧作家测试添加到,并且当我使用playwright _Electron.launch()
启动它时,我有一些SVG文件在我的CSS中使用,以尝试从node_modules/electron/dist/resources/electron.asar
文件,而不是来自webpack /build>/build
目录。从命令行手动启动它可以正常工作,而无需重建或其他任何内容。
当我检查图标 -加载元素在DevTools元素选项卡中,URL显示为这样:
.icon-load {
background: url(file:///F:/Programming/REDACTED/node_modules/electron/dist/resources/electron.asar/renderer/287f560038de84fa9ced.svg);
}
到目前为止,我已经尝试验证bose.baseuri以及_Electron.launch()
上的一些不同选项。
DevTools Console会话:
window.$("body").baseURI
"file:///F:/Programming/REDACTED/build/"
启动-Electron.js:
// Launch Electron app.
const electronApp = await electron.launch({
args: ["."],
//cwd: "F:\\Programming\\REDACTED", // no change
//bypassCSP: true, // no change
});
更新2:刷新页面会导致SVG文件从正确的位置加载!我们似乎有一个种族条件,并在电子发射中具有某种上下文切换。我将再次添加WebPack配置的片段:
module.exports = {
context: __dirname + "/renderer",
entry: "./App.js",
output: {
path: __dirname + "/build",
filename: "bundle.[fullhash].js",
},
stats: {
errorDetails: true,
children: true,
},
module: {
rules: [
{
test: /App\.js$/i,
loader: "expose-loader",
options: {
exposes: {
globalName: "FF",
},
},
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"], // disabling URL loading in CSS loader makes app load but without CSS images
},
{
test: /\.(jpg|png|ico|svg)$/i,
type: "asset/resource",
},
],
},
};
I have an electron app I am trying to add playwright tests to, and when I launch it using the playwright _electron.launch()
, I have some SVG files that are used in my CSS trying to load from the node_modules/electron/dist/resources/electron.asar
file, instead of from the Webpack /build
directory. Launching it manually from the command line works fine, without rebuilding or anything.
Any ideas what could cause this?
When I inspect the icon-load element in devtools element tab, the URL shows up like so:
.icon-load {
background: url(file:///F:/Programming/REDACTED/node_modules/electron/dist/resources/electron.asar/renderer/287f560038de84fa9ced.svg);
}
So far I have tried verifying body.baseURI as well as a few different options on _electron.launch()
.
Devtools console session:
window.$("body").baseURI
"file:///F:/Programming/REDACTED/build/"
launch-electron.js:
// Launch Electron app.
const electronApp = await electron.launch({
args: ["."],
//cwd: "F:\\Programming\\REDACTED", // no change
//bypassCSP: true, // no change
});
Update 2: Refreshing the page causes the SVG files to load from the correct location!! We appear to have a race condition with some kind of context switching in the electron launch. I'll add a snippet of my Webpack config again:
module.exports = {
context: __dirname + "/renderer",
entry: "./App.js",
output: {
path: __dirname + "/build",
filename: "bundle.[fullhash].js",
},
stats: {
errorDetails: true,
children: true,
},
module: {
rules: [
{
test: /App\.js$/i,
loader: "expose-loader",
options: {
exposes: {
globalName: "FF",
},
},
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"], // disabling URL loading in CSS loader makes app load but without CSS images
},
{
test: /\.(jpg|png|ico|svg)$/i,
type: "asset/resource",
},
],
},
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论