No matter what value I set detoxURLBlacklistRegex to in launchArgs when launching the app, it is always nil when picked up in the native code.
If I replace [options arrayForKey:@"detoxURLBlacklistRegex"];with @[@".*"]; my tests run as expected. I've tried setting the values to all of the following:
'\\("http://192.168.1.253:19001/onchange","https://e.crashlytics.com/spi/v2/events"\\)''\\(".*"\\)''\\(.*\\)'['.*']The value should be set to what is passed in detoxURLBlacklistRegex
Omitting the log for brevity. It shows a lot of App State -> busy Waiting for network requests to finish: ... logs while launching
Can you please print NSProcessInfo.processInfo.arguments and post it here? Thanks
I wonder if the syntax of what is passed is perhaps not correctly understood by the system, and thus not parsed correctly as an array, which then returns nil, as you've seen.
I wasn't able to easily print NSProcessInfo.processInfo.arguments from the native side, but I sent it back through the websocket:
[
"/<omitted>/Library/Developer/CoreSimulator/Devices/DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC/data/Containers/Bundle/Application/B4169AF8-137C-4697-B781-ABC8341F6D81/<omitted>.app/Lifion",
"--args",
"-detoxServer",
"ws://localhost:50704",
"-detoxSessionId",
"1206b777-0544-6187-ff96-b6291745ab7c",
"-detoxPrintBusyIdleResources",
"YES",
"-detoxURLBlacklistRegex",
"\\(.*codepush.azurewebsites.*,.*clients3.google.*,.*googleapis.*,.*app-measurement.*,.*crashlytics.*\\)"
]
Relevant logs:
detox[82393] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeLaunchApp({
bundleId: 'com.<omitted>',
deviceId: 'DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC',
launchArgs: {
detoxServer: 'ws://localhost:50704',
detoxSessionId: '1206b777-0544-6187-ff96-b6291745ab7c',
detoxPrintBusyIdleResources: 'YES',
detoxURLBlacklistRegex: '\\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\\)'
}
})
detox[82393] DEBUG: [exec.js/EXEC_CMD, #5] SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="/<omitted>/Library/Detox/ios/6482a19f2e78285efde7a67b977225fd53e12142/Detox.framework/Detox" /usr/bin/xcrun simctl launch DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC com.<omitted> --args -detoxServer "ws://localhost:50704" -detoxSessionId "1206b777-0544-6187-ff96-b6291745ab7c" -detoxPrintBusyIdleResources "YES" -detoxURLBlacklistRegex "\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\)"
detox[82393] DEBUG: [exec.js/EXEC_TRY, #5] Launching com.<omitted>...
detox[82393] TRACE: [exec.js/EXEC_SUCCESS, #5] com.<omitted>: 82430
detox[82393] DEBUG: [exec.js/EXEC_CMD, #6] /usr/bin/xcrun simctl get_app_container DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC com.<omitted>
detox[82393] TRACE: [exec.js/EXEC_SUCCESS, #6] /<omitted>/Library/Developer/CoreSimulator/Devices/DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC/data/Containers/Bundle/Application/B4169AF8-137C-4697-B781-ABC8341F6D81/<omitted>.app
detox[82393] INFO: [AppleSimUtils.js] com.<omitted> launched. To watch simulator logs, run:
/usr/bin/xcrun simctl spawn DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC log stream --level debug --style compact --predicate 'processImagePath beginsWith "/<omitted>/Library/Developer/CoreSimulator/Devices/DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC/data/Containers/Bundle/Application/B4169AF8-137C-4697-B781-ABC8341F6D81/<omitted>.app"'
detox[82430] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onLaunchApp({
bundleId: 'com.<omitted>',
deviceId: 'DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC',
launchArgs: {
detoxServer: 'ws://localhost:50704',
detoxSessionId: '1206b777-0544-6187-ff96-b6291745ab7c',
detoxPrintBusyIdleResources: 'YES',
detoxURLBlacklistRegex: '\\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\\)'
},
pid: 82430
})
Ah, I think the syntax is incorrect. It needs to be an array of strings. You are missing the " for each string. Try with that.
You can see in several places in the second log (example below) that I am passing strings. They're being stripped out somewhere:
detox[82393] TRACE: [ArtifactsManager.js/LIFECYCLE] artifactsManager.onBeforeLaunchApp({
bundleId: 'com.<omitted>',
deviceId: 'DCEDB0BC-2805-4FF4-8F0B-AAA68F2777EC',
launchArgs: {
detoxServer: 'ws://localhost:50704',
detoxSessionId: '1206b777-0544-6187-ff96-b6291745ab7c',
detoxPrintBusyIdleResources: 'YES',
detoxURLBlacklistRegex: '\\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\\)'
}
})
Not good!
@d4vidi @rotemmiz This likely broke after the rewrite of arguments. It means this feature is broken.
Mind linking to the "rewrite of arguments"? I'd love to dive a little deeper into this.
Yikes, are we lacking e2e coverage there? @michaelgmcd have you happened to have tried this out on Android?
A quick note here, setURLBlacklist is a passthrough operation into EarlGrey, it only accepts regex expressions (i.e. https\:\/\/www.google.com.* instead of https://www.google.com.
Try your expressions in a regex matching site (like regex 101) and see if it works.
@rotemmiz The issue is the lack of quotes, because they are stripped. NSUserDefaults then fails to parse the array of strings as such.
@d4vidi I have not tried this on Android. Is it even supported there?
@rotemmiz I tried _a lot_ of different options, including ".*". Will to give any other example a shot.
Hey @LeoNatan, following up here. What are the next steps? I'd love some advice on how to debug this a little better. The "Debugging in XCode" doc doesn't seem to apply here because we're launching the app a different way.
I am not familiar with the JS side of things. If you’d like to help us debug, please follow the launch arguments from the user-facing launch API to where it is actually sent. Somewhere there is a bug that causes incorrect stripping of quotes and possibly other characters. Thanks
I dug a little bit into this and everything up until the native code seems ok. Below (from AppleSimUtils.js) is the only place that manipulates and uses the launch args:
...
_joinLaunchArgs(launchArgs) {
return _.map(launchArgs, (v, k) => `-${k} "${v}"`)
.join(' ')
.trim();
}
async _launchMagically(frameworkPath, udid, bundleId, launchArgs, languageAndLocale) {
const args = this._joinLaunchArgs(launchArgs);
const statusLogs = {
trying: `Launching ${bundleId}...`,
};
let dylibs = `${frameworkPath}/Detox`;
if (process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES) {
dylibs = `${process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES}:${dylibs}`;
}
let launchBin =
`SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="${dylibs}" ` +
`/usr/bin/xcrun simctl launch ${udid} ${bundleId} --args ${args}`;
if (!!languageAndLocale && !!languageAndLocale.language) {
launchBin += ` -AppleLanguages "(${languageAndLocale.language})"`;
}
if (!!languageAndLocale && !!languageAndLocale.locale) {
launchBin += ` -AppleLocale ${languageAndLocale.locale}`;
}
const result = await exec.execWithRetriesAndLogs(launchBin, undefined, statusLogs, 1);
return result;
}
...
The arguments to simctl launch seem correct:
/usr/bin/xcrun simctl launch <omitted> --args -detoxServer "ws://localhost:65313" -detoxSessionId "d6f3d4e7-7a91-7cd6-0423-b679f5cea8eb" -detoxPrintBusyIdleResources "YES" -detoxURLBlacklistRegex "\(".*codepush.azurewebsites.*",".*clients3.google.*",".*googleapis.*",".*app-measurement.*",".*crashlytics.*"\)"
I've tried escaping the " in the launchArgs I pass as well, but still no luck:
'\\(\\".*codepush.azurewebsites.*\\",\\".*clients3.google.*\\",\\".*googleapis.*\\",\\".*app-measurement.*\\",\\".*crashlytics.*\\"\\)'
Any news on this?
@LeoNatan
This likely broke after the rewrite of arguments. It means this feature is broken.
Is there a specific version of Detox we can use in the meantime until this gets sorted out?
I'm sorry, I'm not sure which version introduced this issue. It was a while back. Contributions are welcome.
@michaelgmcd when you escape those " characters,
what is the output you get back from your NSProcessInfo.processInfo.arguments sent through websockets?
is there an easy way to set the logging through websockets up?
Hey @LeoNatan @renanmav @Durisvk
if using detox on v14.0.0
and using:
await device.setURLBlacklist(['.*googleapis.*']);
works for me
@jaburx I'm missing in the docs, when is the right time to call await device.setURLBlacklist(['.*googleapis.*']);
is it before detox.init? after detox.init?
the problem is I'm using detox for Expo ejected app and it gets stuck on init and on setURLBlacklist as well
Sending the param as launch argument and using setURLBlacklist are two different things. The bug is in the former, while the latter passes the data over the web socket.
Its after init
Hey Leo, we know that, but u guys were asking for a way to run it.
But the suggestion doesn't work here, because if an app makes requests on launch, Detox will be stuck waiting for them, unable to reach idle state, so it can process the setURLBlacklist() call.
Hello, I dug into this issue and couldn't find where it was altered. I played with NSUserDefaults and launch args in XCode, and in fact there's no problem with detox.
You can use this function to generate the correct value of detoxURLBlacklistRegex from a list of domains:
const getDetoxURLBlacklistRegexFromDomains = domains =>
'(' + domains.map(domain => `\\".*${domain}.*\\"`).join(',') + ')';
This generates the following CLI arg, with your example @michaelgmcd :
-detoxURLBlacklistRegex "(\".*codepush.azurewebsites.*\",\".*clients3.google.*\",\".*googleapis.*\",\".*app-measurement.*\",\".*crashlytics.*\")"
Happy to do a PR to add a more friendly API if need be.
@Minishlink, it works! Weird that I tried a very similar function that didn't. I think a friendlier API would make sense. Maybe just accept an array of url regex strings?
Is there any solution that doesn’t involve diving into the workings of Detox, and just using the
await detox.init(config, { launchApp: false, detoxURLBlacklistRegex: ""});

If there is (having kept a close eye on this bug) I would be very grateful to know what regex I would need to blacklist pub-nub domains. I.e. ps1.pndsn.com, ps2.pndsn.com, ps3.pndsn.com, ps22.pndsn.com etc etc


I know it would seem straightforward, but nothing seems to work.
Thanks
@mckenzit Have you seen my comment?
You would then have to do :
const detoxURLBlacklistRegex = getDetoxURLBlacklistRegexFromDomains(['pndsn.com']);
await detox.init(config, { launchApp: false, detoxURLBlacklistRegex });
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions!
For more information on bots in this reporsitory, read this discussion.
What's the status here, then? Should we pin or close?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.
Thank you for your contributions!
For more information on bots in this reporsitory, read this discussion.
The issue has been closed for inactivity.
Most helpful comment
@LeoNatan
Is there a specific version of Detox we can use in the meantime until this gets sorted out?