Repository: electron/electron (language: cpp)

Issue:
[Bug]: Warning: Class WebSwapCGLLayer is implemented in both system library and electron distribution
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

18.0.0

### What operating system are you using?

macOS

### Operating System Version

12.3.1

### What arch are you using?

x64

### Last Known Working Electron version

17.3.1

### Expected Behavior

Starting electron using the npm script `"app":  "electron ."` starts the app with no warnings.

### Actual Behavior

Electron starts normally, but with the following warning:

```
Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffa5a006318) and /{path/to/app}/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x10f8a89c8). One of the two will be used. Which one is undefined.
```
(`{path/to/app}` has been substituted for the actual path to the app on my system.)

### Testcase Gist URL

_No response_

### Additional Information

_No response_


Discussion / hints:
@geronimus why didn't you use a proper title for the bug?
Apologies. I don't often do these on github, and the structured form took me a little by surprise.
I have the same problem
```bash
objc[60540]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x7ffa4bc3c318) and /Users/macos/Desktop/ezos-electron-vite/node_modules/.pnpm/electron@18.0.3/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x111a019c8). One of the two will be used. Which one is undefined.

```
`WebSwapCGLLayer` is defined in https://source.chromium.org/chromium/chromium/src/+/main:third_party/angle/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
it can be fixed by applying this patch in third_party/angle
```patch
diff --git a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h
index 783a3dff4..8cfca6aa6 100644
--- a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h
+++ b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h
@@ -17,8 +17,7 @@ typedef _CGLContextObject *CGLContextObj;
 struct __IOSurface;
 typedef __IOSurface *IOSurfaceRef;
 
-// WebKit's build process requires that every Objective-C class name has the prefix "Web".
-@class WebSwapCGLLayer;
+@class SwapCGLLayer;
 
 namespace rx
 {
@@ -87,7 +86,7 @@ class WindowSurfaceCGL : public SurfaceGL
                                               const gl::FramebufferState &state) override;
 
   private:
-    WebSwapCGLLayer *mSwapLayer;
+    SwapCGLLayer *mSwapLayer;
     SharedSwapState mSwapState;
     uint64_t mCurrentSwapId;
 
diff --git a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
index 21894682d..fd95c07df 100644
--- a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
+++ b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
@@ -24,7 +24,7 @@
 #    include "libANGLE/renderer/gl/StateManagerGL.h"
 #    include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
 
-@interface WebSwapCGLLayer : CAOpenGLLayer {
+@interface SwapCGLLayer : CAOpenGLLayer {
     CGLContextObj mDisplayContext;
 
     bool initialized;
@@ -38,7 +38,7 @@ - (id)initWithSharedState:(rx::SharedSwapState *)swapState
             withFunctions:(const rx::FunctionsGL *)functions;
 @end
 
-@implementation WebSwapCGLLayer
+@implementation SwapCGLLayer
 - (id)initWithSharedState:(rx::SharedSwapState *)swapState
               withContext:(CGLContextObj)displayContext
             withFunctions:(const rx::FunctionsGL *)functions
@@ -213,9 +213,9 @@ - (void)drawInCGLContext:(CGLContextObj)glContext
     mSwapState.lastRendered   = &mSwapState.textures[1];
     mSwapState.beingPresented = &mSwapState.textures[2];
 
-    mSwapLayer = [[WebSwapCGLLayer alloc] initWithSharedState:&mSwapState
-                                                  withContext:mContext
-                                                withFunctions:mFunctions];
+    mSwapLayer = [[SwapCGLLayer alloc] initWithSharedState:&mSwapState
+                                               withContext:mContext
+                                             withFunctions:mFunctions];
     [mLayer addSublayer:mSwapLayer];
     [mSwapLayer setContentsScale:[mLayer contentsScale]];
```
@miniak When fix will be available as built in electron package?
Looks like they tried to fix this: https://bugs.chromium.org/p/angleproject/issues/detail?id=5253 but it seems now WebCore has the one they changed it to? Not sure 🤔 
@codebytere LOL, we'll just need to change it to yet another name here to avoid the conflict then.
Does this warning cause any actual problems? I'm on a Mac and get this in my console, but it still seems to work fine. The warning says "which one is undefined" which seems to imply it could be using the wrong one, but so far the Electron app runs OK for me.
As for me it looks like https://github.com/electron/electron/issues/33508 both in dev & packaged mode
Same here: https://github.com/tjx666/electron-vue-vite-boilerplate

<img width="1440" alt="image" src="https://user-images.githubusercontent.com/41773861/169883976-4255c107-3004-4b2c-920d-1e62bfa4b766.png">

@miniak any news? Issue is blocking update on current supported version. 17 is last working version, but not supported by electron team.
<img width="712" alt="截屏2022-05-26 14 32 20" src="https://user-images.githubusercontent.com/76605143/170431158-44c5823f-4295-4ac0-b1f9-f0e54d7e87cc.png">
I have encountered similar problems, but the electronic application is loaded normally. I have encountered some installation problems due to GFW before. I successfully installed it using a reliable yarn source (taoabao)
My running environment is macos12,arm64,electronv19.0.0

`npm install --save-dev electron` 
`"electron": "^19.0.2"`
`electron .` is reproduce
Working fine in "electron": "^17.4.7",. Facing issue in the latest version 19.x.
forgive my poor English, so i use Chinese for it

我也碰到这个问题，不过是我项目结构所导致的，我想实现的是一个项目会有多个界面，所以我打算用vue输出有多个静态入口，不同页面加载对应的静态入口，我的vue.config.js配置中pages会有多个，下边是我项目的结构，这个问题有方法解决么
<img width="844" alt="image" src="https://user-images.githubusercontent.com/10693934/173232095-a998bb90-ad2c-4038-8f65-6597502a76bb.png">

> forgive my poor English, so i use Chinese for it 
I have this problem too，My project directory structure is like this
<img alt="image" width="844" src="https://user-images.githubusercontent.com/10693934/173232095-a998bb90-ad2c-4038-8f65-6597502a76bb.png">
this project is vue and static page entry have two(main and about) and this is demo, I can provide project source code if necessary

Results printed on the console when the project is started (node:21660: second warning can be ignored)：
(node:21660) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/changyong/workspace/gitlab/electron/com_me/dist_electron/package.json' of 'background.js'. Please either fix that or report it to the module author
(Use `Electron --trace-deprecation ...` to show where the warning was created)
(node:21660) ExtensionLoadWarning: Warnings loading extension at /Users/changyong/Library/Application Support/com_me/extensions/nhdogjmejiglipccpnnnanhbledajbpd:
  Manifest version 2 is deprecated, and support will be removed in 2023. See https://developer.chrome.com/blog/mv2-transition/ for more details.
objc[21661]: Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x24a27f808) and /Users/changyong/workspace/gitlab/electron/com_me/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x10734d348). One of the two will be used. Which one is undefined.
Can you speak in English please, guys? I'm observing the situation here as this bug affects my app as well :(
Is there a way to suppress the output/error? I'm using chrome headless and this output appears to be interrupting the workflow. Thank you!
Same issue here, any fix?
> Same issue here, any fix?

I think no~ because, i still console that with using the latest version, just now now now
Follow progress
> Follow progress

x2
Please just subscribe to the issue rather than comment
Commenting  is a way to bring attention. Sorry if this is not allowed, will subscribe now. 
Feel free to follow https://bugs.chromium.org/p/angleproject/issues/detail?id=7123. That is where upstream progress is being tracked.
## Q:

<img width="1310" alt="image" src="https://user-images.githubusercontent.com/7291672/181731682-c94a0ad2-f7a4-435a-a0e6-4cd355e089c2.png">

## A: 

TODO



Hi! electron@20.0.1 the same problem

<img width="384" alt="image" src="https://user-images.githubusercontent.com/6079139/183160193-f9a90c53-06d0-44b0-9253-8b27cc58430d.png">

need to add tag 20.x.y
Hey,

v20.0.2 the same issue
There is no indication in this issue thread that it has been fixed, continually posting "Version {random} same issue" comments is not helpful to anyone and only serves to spam maintainers who are subscribed to these updates.  I'll be locking this issue temporarily to avoid such comments.

Following https://bugs.chromium.org/p/angleproject/issues/detail?id=5253 is your best bet
@MarshallOfSound we need to patch it ourselves. WebKit on Mac is also using ANGLE and will be exporting the symbol. Chromium / Electron needs to use a different name for it.

Fix patch:
diff --git a/patches/angle/.patches b/patches/angle/.patches
new file mode 100644
index 0000000000000..ca864b58a91d0
--- /dev/null
+++ b/patches/angle/.patches
@@ -0,0 +1,1 @@
+fix_rename_webswapcgllayer_to_webswapcgllayerchromium.patch
diff --git a/patches/angle/fix_rename_webswapcgllayer_to_webswapcgllayerchromium.patch b/patches/angle/fix_rename_webswapcgllayer_to_webswapcgllayerchromium.patch
new file mode 100644
index 0000000000000..a13e32902ade5
--- /dev/null
+++ b/patches/angle/fix_rename_webswapcgllayer_to_webswapcgllayerchromium.patch
@@ -0,0 +1,66 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Milan Burda <milan.burda@gmail.com>
+Date: Mon, 10 Oct 2022 15:11:08 +0400
+Subject: fix: rename WebSwapCGLLayer to WebSwapCGLLayerChromium
+
+Class WebSwapCGLLayer is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Frameworks/libANGLE-shared.dylib (0x23c589b50)
+and src/out/testing/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libGLESv2.dylib (0x1123f8488).
+One of the two will be used. Which one is undefined.
+
+diff --git a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h
+index 7101cd271c07e604c6f5241d1a22f59f446c0033..98a89976f87e32a66bd504951698204fad938d57 100644
+--- a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h
++++ b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.h
+@@ -18,7 +18,7 @@ struct __IOSurface;
+ typedef __IOSurface *IOSurfaceRef;
+ 
+ // WebKit's build process requires that every Objective-C class name has the prefix "Web".
+-@class WebSwapCGLLayer;
++@class WebSwapCGLLayerChromium;
+ 
+ namespace rx
+ {
+@@ -89,7 +89,7 @@ class WindowSurfaceCGL : public SurfaceGL
+                                      gl::Framebuffer *framebuffer) override;
+ 
+   private:
+-    WebSwapCGLLayer *mSwapLayer;
++    WebSwapCGLLayerChromium *mSwapLayer;
+     SharedSwapState mSwapState;
+     uint64_t mCurrentSwapId;
+ 
+diff --git a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
+index 27990e9c2facbbe0e30f4b275e0778a6474fb9ce..84f9fa9b6d31fb0e85a4c4270dff4d935f855c26 100644
+--- a/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
++++ b/src/libANGLE/renderer/gl/cgl/WindowSurfaceCGL.mm
+@@ -24,7 +24,7 @@
+ #    include "libANGLE/renderer/gl/StateManagerGL.h"
+ #    include "libANGLE/renderer/gl/cgl/DisplayCGL.h"
+ 
+-@interface WebSwapCGLLayer : CAOpenGLLayer {
++@interface WebSwapCGLLayerChromium : CAOpenGLLayer {
+     CGLContextObj mDisplayContext;
+ 
+     bool initialized;
+@@ -38,7 +38,7 @@ - (id)initWithSharedState:(rx::SharedSwapState *)swapState
+             withFunctions:(const rx::FunctionsGL *)functions;
+ @end
+ 
+-@implementation WebSwapCGLLayer
++@implementation WebSwapCGLLayerChromium
+ - (id)initWithSharedState:(rx::SharedSwapState *)swapState
+               withContext:(CGLContextObj)displayContext
+             withFunctions:(const rx::FunctionsGL *)functions
+@@ -220,9 +220,9 @@ - (void)drawInCGLContext:(CGLContextObj)glContext
+     mSwapState.lastRendered   = &mSwapState.textures[1];
+     mSwapState.beingPresented = &mSwapState.textures[2];
+ 
+-    mSwapLayer = [[WebSwapCGLLayer alloc] initWithSharedState:&mSwapState
+-                                                  withContext:mContext
+-                                                withFunctions:mFunctions];
++    mSwapLayer = [[WebSwapCGLLayerChromium alloc] initWithSharedState:&mSwapState
++                                                          withContext:mContext
++                                                        withFunctions:mFunctions];
+     [mLayer addSublayer:mSwapLayer];
+     [mSwapLayer setContentsScale:[mLayer contentsScale]];
+ 
diff --git a/patches/config.json b/patches/config.json
index bbf0d46409474..bac8c8b9a4586 100644
--- a/patches/config.json
+++ b/patches/config.json
@@ -1,6 +1,8 @@
 {
   "src/electron/patches/chromium": "src",
 
+  "src/electron/patches/angle": "src/third_party/angle",
+
   "src/electron/patches/boringssl": "src/third_party/boringssl/src",
 
   "src/electron/patches/devtools_frontend": "src/third_party/devtools-frontend/src",


Test patch: