Elon Musk offered Amber Heard "24/7 security" after she told him she wanted a restraining order against Johnny Depp, the High Court has heard.
She denied Mr Musk visited her while her then-husband Mr Depp was away.
Mr Depp, 57, is suing the publisher of the Sun over an article that labelled him a "wife beater" - but the newspaper insists it was accurate.
The US actress, 34, was giving evidence in London for a second day on the 11th day of her ex-husband's libel action.
She dismissed suggestions Mr Musk visited her in 2015 while Mr Depp was away, saying she was not in touch with the Tesla founder until the following year.
On Tuesday, Mr Depp's lawyer, Eleanor Laws QC, questioned Ms Heard on her statement, in which the lawyer said the actress had indicated that Mr Depp was "illogically jealous" and that she wasn't having any "illicit relationships".
The trial judge, Mr Justice Nicol, intervened to say the word "illicit.
carries a connotation".
The lawyer read out text messages between Ms Heard and Mr Musk from 22 May 2016, in which Ms Heard told him that she was going to get a restraining order against Mr Depp.
The messages came a day after an alleged incident at the Eastern Columbia Building in Los Angeles, where Mr Depp and Ms Heard lived, in which the actress claims Mr Depp threw her mobile phone at her, hitting her in the face - which the actor denies.
Questioning Ms Heard, Ms Laws said Mr Musk offered to "arrange 24/7 security for you", adding that he said: "The offer would stand, even if you never wanted to see me again.
anyway, sorry for being an idiot.
The radio silence hurts a lot.
It only matters because I really like you.
" The barrister cited evidence from Alejandro Romero, a concierge at the Eastern Columbia Building, who said he saw Mr Musk visiting Ms Heard "when Mr Depp was in Australia".
Ms Heard said Mr Romero was "wrong", insisting that she wasn't in communication with Mr Musk until 2016.
In his written witness statement, Mr Romero said: "From March 2015 onwards, Ms Heard was visited regularly late at night, at around 11pm to midnight, by Mr Elon Musk.
" The concierge claimed Ms Heard gave Mr Musk his own fob to access the building.
Ms Laws later put it to the actress that in March 2015, she was in a "relationship or seeing" Mr Musk, which Ms Heard denied.
Ms Heard has said that Mr Depp accused her of having affairs with fellow actors, including James Franco - with whom she starred in the film The Adderall Diaries.
Mr Depp's lawyer asked Ms Heard about Mr Franco and her comment in her statement that he was "someone that Mr Depp was accusing you of having an affair with and he was quite wrong about it".
Ms Heard said: "That's right.
" The lawyer showed the court CCTV footage of the actress travelling downstairs in the lift at the Eastern Columbia Building on 22 May 2016 at around 23:00 local time (06:00 BST), before travelling back upstairs shortly after with Mr Franco.
After Ms Heard confirmed that the man in the footage was Mr Franco, Ms Laws asked her if she was trying to "avoid" being seen by the camera.
Ms Heard replied that the pair were "talking" and Mr Franco was saying to her "'oh my god, what happened to you?' when he saw her face.
Ms Heard said she collected Mr Franco from downstairs after 23:00 local time, before adding that "in those days, I didn't sleep much at night".
Bed defecation 'absolutely disgusting' Ms Laws turned to an alleged incident in which Mr Depp's cleaner was said to have found faeces in his bed the morning after Ms Heard's 30th birthday party at the Eastern Columbia Building.
Mr Depp has previously said it was "a mystery" who defecated in the bed "and it was not left by a three or four-pound dog", in reference to the couple's dogs.
He said he was "convinced" that Ms Heard or "one of her cohort" had defecated on the bed.
Ms Heard denied that she or any of her friends had left "human excrement" on the bed when challenged by Ms Laws, calling such an act "absolutely disgusting".
Asked about the couple's dog and its problem with toilet training, Ms Heard said it had become a "common occurrence" after one of the dogs ate some of Mr Depp's cannabis as a puppy.
She said Mr Depp's housekeeper Hilda Vargas would clean up after the dogs "occasionally" but that when her ex-husband's dog had accidents in the bed she herself would clean it up.
Ms Laws said Ms Vargas "knew the difference" between the mess the couples' dogs made and human faeces, and asked Ms Heard if Ms Vargas was wrong.
Ms Heard said: "I can't imagine what kind of human being would have a sense of humour like that, other than Johnny, but I don't think that's funny, I think it's horrific.
" 'I hit him to protect my sister' Ms Heard was asked about the alleged "stairs incident" in LA in March 2015, when the actress has said she thought Mr Depp was going to push her sister, Whitney Henriquez, down the stairs.
Mr Depp's barrister put it to Ms Heard that she "was the violent one" in the "very nasty row" between the actress and her now ex-husband.
Ms Heard replied that Mr Depp had hit her and her sister, and denied Ms Law's suggestions that she threw a can of Red Bull and spat at him.
She admitted striking Mr Depp "in defence" of her sister, as she thought he was "about to push her down the stairs".
Ms Heard said this belief was based on a "rumour" she had heard from "two people" that Mr Depp had "pushed a former girlfriend", which she thought was Kate Moss, down the stairs.
The actress said she would "never forget" the incident in LA, as it was the "first time" she had hit him back in all the "years" she claimed Mr Depp had hit her.
Ms Laws challenged Ms Heard that she had never mentioned the claim about Ms Moss before, suggesting the actress was "making this up as you go along".
Ms Heard said that she didn't have "the opportunity (to list) every instance of every moment of every memory that has gone through my mind".
The libel case centres on an article published on the Sun's website in April 2018 headlined: "Gone Potty: How can JK Rowling be 'genuinely happy' casting wife beater Johnny Depp in the new Fantastic Beasts film?".
The article related to allegations made by Ms Heard, which Mr Depp denies.
Her evidence was initially due to conclude on Wednesday but will now continue until Thursday morning, with her friends Melanie Inglessis and Joshua Drew expected to appear by videolink on Wednesday afternoon.