Migrate AppExt UserDefaults Data to WebExt

Hi,
I am working on converting my Safari App Extension to Web Extension, I stored some data in App Extension by using
Code Block swift
UserDefaults(suiteName: "my-app-extension")

Now, I am trying to copy all these data to Web Extension background page.
To achieve that, I send a native message from background page, and in the SafariWebExtensionHandler.swift, I tried to use the UserDefaults with the same suiteName, but seems I can't get any data.

Any solution or suggestions to this problem?

Thank you!
It is related to using shared UserDefaults among different targets.
To do that, I need to set both the AppExtension and WebExtension to the same app group.
Unfortunately, my AppExtension doesn't have app group before, after I set the AppExtension to an app group ("my-app-extension", same as the suiteName in getting UserDefaults), The AppExtension can't get the previous storages.
Looks it is impossible to resolve the issue.
You might be able to try an intermediate update where you write the contents of your UserDefaults (without an app group) to a file, and then another update where you read the contents of that file (in your App Sandbox) and write it to your newly created app groups's defaults.
Thanks bweinstein, that's sounds a plan.

Actually, I tried the FileManager.default, if I can copy files across different targets, e.g, copying the AppExt's UserDefaults file my-app-extension.plist to file:///Users/<username>/Library/Containers/<WebExt bundle identifier>/Data/Library/Preferences, problem is solved. But seems FileManager.default can only operate file in current process files.
Migrate AppExt UserDefaults Data to WebExt
 
 
Q