Skip to content

Commit 02041d3

Browse files
committed
feat: load file URLs with base URL to prevent CORS errors
1 parent 1c4cd48 commit 02041d3

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

Plugins/Mac/Sources/ImmutableWebView.mm

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,32 @@ - (void)loadURL:(const char *)url
322322
{
323323
if (webView == nil)
324324
return;
325-
325+
326326
WKWebView *_webView = (WKWebView *)webView;
327327
NSString *urlStr = [NSString stringWithUTF8String:url];
328328
NSURL *nsurl = [NSURL URLWithString:urlStr];
329-
NSURLRequest *request = [NSURLRequest requestWithURL:nsurl];
330-
[_webView load:request];
329+
330+
// Check if it's a file URL
331+
if ([nsurl.scheme isEqualToString:@"file"]) {
332+
// Load file content as HTML string with a proper base URL
333+
NSError *error = nil;
334+
NSString *htmlString = [NSString stringWithContentsOfURL:nsurl
335+
encoding:NSUTF8StringEncoding
336+
error:&error];
337+
338+
if (error) {
339+
NSLog(@"Error loading file: %@", error.localizedDescription);
340+
return;
341+
}
342+
343+
// Use http://localhost as base URL to avoid null origin
344+
NSURL *baseURL = [NSURL URLWithString:@"http://localhost/"];
345+
[_webView loadHTMLString:htmlString baseURL:baseURL];
346+
} else {
347+
// Load remote URLs normally
348+
NSURLRequest *request = [NSURLRequest requestWithURL:nsurl];
349+
[_webView loadRequest:request];
350+
}
331351
}
332352

333353
- (void)launchAuthURL:(const char *)url redirectUri:(const char *)redirectUri

src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/ImmutableWebView.bundle/Contents/Info.plist

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>BuildMachineOSBuild</key>
6-
<string>23G93</string>
6+
<string>25B78</string>
77
<key>CFBundleDevelopmentRegion</key>
88
<string>English</string>
99
<key>CFBundleExecutable</key>
@@ -29,19 +29,19 @@
2929
<key>DTCompiler</key>
3030
<string>com.apple.compilers.llvm.clang.1_0</string>
3131
<key>DTPlatformBuild</key>
32-
<string>24A336</string>
32+
<string>25B74</string>
3333
<key>DTPlatformName</key>
3434
<string>macosx</string>
3535
<key>DTPlatformVersion</key>
36-
<string>15.0</string>
36+
<string>26.1</string>
3737
<key>DTSDKBuild</key>
38-
<string>24A336</string>
38+
<string>25B74</string>
3939
<key>DTSDKName</key>
40-
<string>macosx15.0</string>
40+
<string>macosx26.1</string>
4141
<key>DTXcode</key>
42-
<string>1600</string>
42+
<string>2611</string>
4343
<key>DTXcodeBuild</key>
44-
<string>16A242d</string>
44+
<string>17B100</string>
4545
<key>LSMinimumSystemVersion</key>
4646
<string>12.4</string>
4747
</dict>

0 commit comments

Comments
 (0)