I've already solved it by "modifying FileBrower.as" do you think it's correct
to commit it?
public function browse():void
{
COMPILE::SWF
{
delegate.browse();
}
COMPILE::JS
{
focusedButton = document.activeElement as
WrappedHTMLElement;
//trace("activeElement is: " + focusedButton);
focusedButton.addEventListener("blur",
blurHandler);
focusedButton.addEventListener("focus",
focusHandler);
window.addEventListener("keydown", keyHandler);
window.addEventListener("mousemove",
mouseHandler);
window.addEventListener("mousedown",
mouseHandler);
//delegate.click();
focusedButton.addEventListener("click",
clickHandler);
focusedButton.click();
focusedButton.removeEventListener("click",
clickHandler);
}
}
//New
COMPILE::JS
private function clickHandler(e:Object):void
{
delegate.click();
}
This way there are no problems, everything is legal for Chrome, BUT the same
problem occurs again as https://github.com/apache/royale-asjs/issues/886
If I increase the CANCEL_TIMEOUT constant to 250, everything works fine.
What would be the best way to change the value of the static constant
CANCEL_TIMEOUT?
Hiedra
-----Mensaje original-----
De: Josh Tynjala <[email protected]>
Enviado el: lunes, 14 de abril de 2025 21:21
Para: [email protected]
Asunto: Re: mx.net.FileReference chrome
I just tested one of my non-Royale apps that calls click() on the <input
type="file"> element. It still works in that app when tested in Chrome.
It's a very similar situation, where I have a separate <div> element with a
"click" listener, and the listener calls click() on the <input type="file">
element.
Perhaps you should add a breakpoint in the debugger and check what your call
stack looks like. Maybe there's a clue there.
--
Josh Tynjala
Bowler Hat LLC
https://bowlerhat.dev/
On Mon, Apr 14, 2025 at 11:37 AM Maria Jose Esteve <[email protected]>
wrote:
> Yes, I understand the problem; it's not new, and I understand that
> Chrome must have tightened this policy.
>
> I'm wondering if, just as we added the Input-Type-file (delegate), it
> would be appropriate to add a "hidden button" that would call
> delegate.browser.
>
> I've run a test. I created a button in the createDelegate() function,
> called delegateFileButton, and in its "click" event I called
> delegate.click [1] and in the browse function I launched a
> delegateFileButton.click() [2] but it didn't work. ☹ (In FireFox it
> still works fine)
>
>
>
> [1]
>
> COMPILE::JS
>
> public function createDelegate():void
>
> {
>
> delegate =
> document.createElement('input') as WrappedHTMLElement;
>
>
> delegate.setAttribute('type', 'file');
>
>
> goog.events.listen(delegate, 'change', fileChangeHandler);
>
>
>
> delegateFileButton =
> document.createElement('button') as WrappedHTMLElement;
>
>
> delegateFileButton.style.display = "none";
>
>
> delegateFileButton.onclick = function():void {
>
>
> delegate.click();
>
> };
>
> // I have also tried this:
>
> /*
>
>
> goog.events.listen(delegateFileButton, 'click',
>
> function():void {
>
>
> delegate.click();
>
> } );
>
> */
>
> }
>
> [2] public function browse():void
>
> {
>
> COMPILE::SWF
>
> {
>
>
> delegate.browse();
>
> }
>
> COMPILE::JS
>
> {
>
>
> focusedButton = document.activeElement as WrappedHTMLElement;
>
>
> //trace("activeElement is: " + focusedButton);
>
>
> focusedButton.addEventListener("blur", blurHandler);
>
>
> focusedButton.addEventListener("focus", focusHandler);
>
>
> window.addEventListener("keydown", keyHandler);
>
>
> window.addEventListener("mousemove", mouseHandler);
>
>
> window.addEventListener("mousedown", mouseHandler);
>
>
> delegateFileButton.click();
>
> }
>
> }
>
>
>
>
>
> Hiedra
>
>
>
> -----Mensaje original-----
> De: Josh Tynjala <[email protected]<mailto:
> [email protected]>>
> Enviado el: lunes, 14 de abril de 2025 19:36
> Para: [email protected]<mailto:[email protected]>
> Asunto: Re: mx.net.FileReference chrome
>
>
>
> Browsers have certain security restrictions where you can't call
> certain APIs unless the user has interacted with the page in some way.
> In this case, if you want to call FileReference.browse(), it must be
> triggered by a listener for a user gesture, such as mouse click or key down.
>
>
>
> --
>
> Josh Tynjala
>
> Bowler Hat LLC
>
> https://bowlerhat.dev/
>
>
>
>
>
> On Mon, Apr 14, 2025 at 9:42 AM Maria Jose Esteve <[email protected]
> <mailto:[email protected]>> wrote:
>
>
>
> > Hi,
>
> > I need your help because I'm stuck.
>
> > In one of my applications, I use mx.net.FileReference to select a
>
> > user's photo.
>
> > It's always worked fine for me, but yesterday, while testing, I
>
> > noticed that it stopped working in Chrome, although it still works
> > as
>
> > expected in Firefox.
>
> > I'm not getting any errors, but I do see a warning in the debug console:
>
> > "File chooser dialog can only be shown with a user activation."
>
> > The traceback points to org.apache.royale.file.beads.FileBrowser in
>
> > the
>
> > browse() method:
>
> >
>
> > public function browse():void
>
> > {
>
> > COMPILE::SWF
>
> > {
>
> > delegate.browse();
>
> > }
>
> > COMPILE::JS
>
> > {
>
> > focusedButton = document.activeElement as
>
> > WrappedHTMLElement;
>
> > //trace("activeElement is: " + focusedButton);
>
> > focusedButton.addEventListener("blur", blurHandler);
>
> > focusedButton.addEventListener("focus",
> > focusHandler);
>
> > window.addEventListener("keydown", keyHandler);
>
> > window.addEventListener("mousemove", mouseHandler);
>
> > window.addEventListener("mousedown", mouseHandler);
>
> > delegate.click(); // <<<<<<<<<<
>
> > -------------------------- Error
>
> > }
>
> > }
>
> >
>
> > I've verified that the delegate is still valid; it references the
>
> > "input, type file" that's created.
>
> > Any ideas on how to fix this?
>
> >
>
> > Thx.
>
> > Hiedra
>
> >
>
> >
>