Solved Live chat disabled due to CORS No 'Access-Control-Allow-Origin' header is present on the requested resource

Status
Not open for further replies.

3CExperience

SOHO User
Joined
Aug 10, 2023
Messages
7
Reaction score
1
Hello,
I have a single 3CX instance which serves several 3CX chats on WordPress websites hosted on o2switch.fr
On some websites, the chat is enabled
And on some websites, the chat is disabled:
The issue is displayed in the network section of the developer console is:

www.w*****i.fr/:1 Access to fetch at 'https://cap*****.my3cx.fr/MyPhone/config/LiveChat**' from origin 'https://www.w****i.fr' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
cap*****.my3cx.fr/MyPhone/config/LiveChat**:1

Failed to load resource: net::ERR_FAILED

www.w*****r/:1 Access to fetch at 'https://c******.my3cx.fr/MyPhone/c2cinfo?c2cid=LiveChat**' from origin 'https://www.w****.fr' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
cap*****.my3cx.fr/MyPhone/c2cinfo?c2cid=LiveChat**:1

Failed to load resource: net::ERR_FAILED

Of course, my https://cap*****.my3cx.fr/webclient/ > Admin > Voice & chat does have the appropriate "Live Chat 3CX" configured and displaying with a green dot in front.
We are during office hours.
There are people in the group...

I've tried desactivating all WP plugins other than 3CX.
I've tried lowering security rules.

What I don't get is that it's working for some sites and not for others...

Any idea?
 
Have you sorted out the issue?
 
@PatrickS What is your exact issue with the Live Chat?
 
Hi @TheodorosG_3CX

We attempted to activate 3CX LiveChat on a WordPress website. Unfortunately, we encountered a disabled chat button, which appears to be related to a CORS issue. Our Google search directed us to this thread for assistance.

2024-07-03_15-57-17.PNG


We did put the server name in the 3cx management console: https://xxxxx/

2024-07-03_16-03-58.PNG
 
tried, same error.
 
Can you use only one url and check?
 
Yes, I did, but it still has the same error.
 
Are you running any antivirus that might be blocking the live chat?
 
We set up a test machine with a fresh install of Windows 11, no antivirus, same error.

We also manually enabled CORS through the Nginx of the 3CX PBX server; it bypassed the CORS check.

The following rules were added to the location /Myphone
2024-07-03_18-13-58.PNG

The result has changed from CORS to 404
2024-07-03_18-09-50.PNG
 
The 404 can be related with the format of the url, have you also tried all options?
 
I don't get what "all options" means. Are you referring to some config option values?
 
The website we tried to embed 3cx talk did not start with www. Instead, it started with 'doc.' If that's the issue, we may need to change it to another domain name.
 
We setup another test server starting with www. the same error persisted.
 
I suspect it's because /MyPhone/c2cinfo?c2cid=LiveChatxxxx returns a 500 server internal error because another CORS request actually succeeded.

2024-07-04_01-14-24.PNG

The error is disguised as a CORS error because, with 500, nothing has been returned; thus, there is no CORS header.

2024-07-04_00-58-42.PNG

Nginx config shows that all URL under /MyPhone/.. was handled by proxy (if not a local file, which is valid for the above cases)

2024-07-04_01-03-28.PNG

Are there any error logs that we can inspect for the @proxy block? http://mc seems to be the shorthand for the management console
 
After tracing the log I found exceptions of 3CX management console: It logged when processing c2cInfo.

Code:
2024/07/03 23:14:57.968|94413|0003|Verb|Null timezone for group 'TestDepartment' (using local time)
2024/07/03 23:14:57.968|94413|0003|Verb|Local time for group 'TestDepartment' is 3/7/2024 11:14:57 pm
2024/07/03 23:14:57.975|94413|0003|Verb|Null timezone for group 'TestDepartment' (using local time)
2024/07/03 23:14:57.975|94413|0003|Verb|Local time for group 'TestDepartment' is 3/7/2024 11:14:57 pm
2024/07/03 23:14:57.975|94413|0003|Info|Route is undefined
2024/07/03 23:14:57.976|94413|0003|Trac|[Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker] Executed action ManagementConsoleJS.MyPhone.MyPhoneController.C2cInfo (3CXManagementConsole) in 14.9289ms
2024/07/03 23:14:57.976|94413|0003|Trac|[Microsoft.AspNetCore.Routing.EndpointMiddleware] Executed endpoint 'ManagementConsoleJS.MyPhone.MyPhoneController.C2cInfo (3CXManagementConsole)'
2024/07/03 23:14:57.983|94413|0003|Excpt|System.NullReferenceException: Object reference not set to an instance of an object.
   at ManagementConsoleJS.MyPhone.MyPhoneController.IsDnAvailable(IPhoneSystem ps, DN dn)
   at ManagementConsoleJS.MyPhone.MyPhoneController.C2cInfo(String c2cid, WebsiteLinksHelper websiteLinks, LiveChatConfigurationService configService)
   at lambda_method1861(Closure, Object, Object[])
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at ManagementConsoleJS.Middleware.ErrorLoggingMiddleware.Invoke(HttpContext context)

After I set the timezone for the TestDepartment,the exception is gone, but still ended with 500 internal error

Code:
2024/07/04 01:54:29.900|0003|Debg| Local time for group 'Test Team' is 4/7/2024 1:54:29 am
2024/07/04 01:54:29.902|0003|Debg| Local time for group 'Test Team' is 4/7/2024 1:54:29 am
2024/07/04 01:54:29.903|0003|Info| Route is undefined
2024/07/04 01:54:29.904|0003|Info| [Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker] Executed action ManagementConsoleJS.Controllers.MyPhoneRequestController.C2cInfo (3CXManagementConsole) in 6.0126ms
2024/07/04 01:54:29.905|0003|Debg| [ManagementConsoleJS.Middleware.ErrorLoggingMiddleware] Unexpected: Object reference not set to an instance of an object.
2024/07/04 01:54:29.907|0003|Info| [Http] -1.2.3.4 GET https://[3cx-pbx]:443/MyPhone/c2cinfo?c2cid=LiveChat59676 - 200 - - 9.6658ms

The error is related to the "route is undefined". I'm not sure which route it is this referring to.

I changed the office hour to whole-day, 24 hours, still got Route is undefined.
 
Finally, the problem was solved.

2024-07-04_02-46-17.PNG

in addition, CORS support multiple sites:

2024-07-04_02-50-46.PNG

It may also explain why some of them work, but others do not. @3CExperience
 
Last edited:
  • Like
Reactions: Matschek and w3data
I'm glad that the issue is resolved ;)
 
Status
Not open for further replies.

Forum statistics

Threads
111,973
Messages
590,078
Members
164,896
Latest member
sameage