Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

popup url addres

Post Reply
w1ld32
Posts: 19
Joined: Wed Feb 12, 2020 10:28 am

popup url addres

Post by w1ld32 »

how to get an address popup window?

Code: Select all

procedure TChildForm.Chromium1BeforePopup(Sender: TObject;
  const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
  targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
  userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
  var windowInfo: TCefWindowInfo; var client: ICefClient;
  var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue;
  var noJavascriptAccess: Boolean;
  var Result: Boolean);
begin
  case targetDisposition of
    WOD_NEW_FOREGROUND_TAB,
    WOD_NEW_BACKGROUND_TAB,
    WOD_NEW_WINDOW : begin
                      Chromium2.LoadURL(targetUrl);
                      Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
                     end; 

    WOD_NEW_POPUP  : begin
    		      ShowMessage(targetUrl);	
                      FPopup             := TPopup.Create(self);
                      Result := not(CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures));
                    end

    else Result := False;
  end;
end;
ShowMessage(targetUrl); = about:blank.
but CreateClientHandler creates a new window and loads required Url;
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: popup url addres

Post by salvadordf »

If you want to redirect the popup window try using the TChromium.OnBeforeResourceLoad event in the new popup window and set request.Url
w1ld32
Posts: 19
Joined: Wed Feb 12, 2020 10:28 am

Re: popup url addres

Post by w1ld32 »

Thank you, Salvador. Please tell me how to properly close 25 windows with 2 browsers in each? And when 50 browsers work for a long time, the error 0xc0000005 crashes. how can I fix it?
w1ld32
Posts: 19
Joined: Wed Feb 12, 2020 10:28 am

Re: popup url addres

Post by w1ld32 »

salvadordf wrote: Tue Jun 30, 2020 7:12 am If you want to redirect the popup window try using the TChromium.OnBeforeResourceLoad event in the new popup window and set request.Url
This didn't help, I need to get the link before opening popup window(
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: popup url addres

Post by salvadordf »

Here are the code comments for that event in the CEF source code :
https://github.com/chromiumembedded/cef ... capi.h#L63

Code: Select all

  ///
  // Called on the UI thread before a new popup browser is created. The
  // |browser| and |frame| values represent the source of the popup request. The
  // |target_url| and |target_frame_name| values indicate where the popup
  // browser should navigate and may be NULL if not specified with the request.
  // The |target_disposition| value indicates where the user intended to open
  // the popup (e.g. current tab, new tab, etc). The |user_gesture| value will
  // be true (1) if the popup was opened via explicit user gesture (e.g.
  // clicking a link) or false (0) if the popup opened automatically (e.g. via
  // the DomContentLoaded event). The |popupFeatures| structure contains
  // additional information about the requested popup window. To allow creation
  // of the popup browser optionally modify |windowInfo|, |client|, |settings|
  // and |no_javascript_access| and return false (0). To cancel creation of the
  // popup browser return true (1). The |client| and |settings| values will
  // default to the source browser's values. If the |no_javascript_access| value
  // is set to false (0) the new browser will not be scriptable and may not be
  // hosted in the same renderer process as the source browser. Any
  // modifications to |windowInfo| will be ignored if the parent browser is
  // wrapped in a cef_browser_view_t. Popup browser creation will be canceled if
  // the parent browser is destroyed before the popup browser creation completes
  // (indicated by a call to OnAfterCreated for the popup browser). The
  // |extra_info| parameter provides an opportunity to specify extra information
  // specific to the created popup browser that will be passed to
  // cef_render_process_handler_t::on_browser_created() in the render process.
  ///
target_url may have the URL of the new popup window but it may be empty.

If you want to cancel the creation of the new popup window set the Result parameter to True.

If the target_url is empty then you can also use the TChromium.OnBeforeBrowse event to cancel the navigation.
https://magpcss.org/ceforum/apidocs3/pr ... bool,bool)

As you can see, the popup window creation in Chromium is complicated and this event is executed in a CEF thread which makes things even more complicated because the VCL should only be handled in the main application thread.

You can let CEF create the popup windows as shown in the MiniBrowser demo but you can also use Delphi forms as you can see in the PopupBrowser2 demo.

In all cases, you have to close all the browsers properly before shutting down the application. Follow the destruction steps in the demo you used as the template for your application or follow the steps in the ToolboxBrowser if you have many open browsers.
w1ld32
Posts: 19
Joined: Wed Feb 12, 2020 10:28 am

Re: popup url addres

Post by w1ld32 »

salvadordf wrote: Wed Jul 01, 2020 2:44 pm Here are the code comments for that event in the CEF source code :
https://github.com/chromiumembedded/cef ... capi.h#L63

Code: Select all

  ///
  // Called on the UI thread before a new popup browser is created. The
  // |browser| and |frame| values represent the source of the popup request. The
  // |target_url| and |target_frame_name| values indicate where the popup
  // browser should navigate and may be NULL if not specified with the request.
  // The |target_disposition| value indicates where the user intended to open
  // the popup (e.g. current tab, new tab, etc). The |user_gesture| value will
  // be true (1) if the popup was opened via explicit user gesture (e.g.
  // clicking a link) or false (0) if the popup opened automatically (e.g. via
  // the DomContentLoaded event). The |popupFeatures| structure contains
  // additional information about the requested popup window. To allow creation
  // of the popup browser optionally modify |windowInfo|, |client|, |settings|
  // and |no_javascript_access| and return false (0). To cancel creation of the
  // popup browser return true (1). The |client| and |settings| values will
  // default to the source browser's values. If the |no_javascript_access| value
  // is set to false (0) the new browser will not be scriptable and may not be
  // hosted in the same renderer process as the source browser. Any
  // modifications to |windowInfo| will be ignored if the parent browser is
  // wrapped in a cef_browser_view_t. Popup browser creation will be canceled if
  // the parent browser is destroyed before the popup browser creation completes
  // (indicated by a call to OnAfterCreated for the popup browser). The
  // |extra_info| parameter provides an opportunity to specify extra information
  // specific to the created popup browser that will be passed to
  // cef_render_process_handler_t::on_browser_created() in the render process.
  ///
target_url may have the URL of the new popup window but it may be empty.

If you want to cancel the creation of the new popup window set the Result parameter to True.

If the target_url is empty then you can also use the TChromium.OnBeforeBrowse event to cancel the navigation.
https://magpcss.org/ceforum/apidocs3/pr ... bool,bool)

As you can see, the popup window creation in Chromium is complicated and this event is executed in a CEF thread which makes things even more complicated because the VCL should only be handled in the main application thread.

You can let CEF create the popup windows as shown in the MiniBrowser demo but you can also use Delphi forms as you can see in the PopupBrowser2 demo.

In all cases, you have to close all the browsers properly before shutting down the application. Follow the destruction steps in the demo you used as the template for your application or follow the steps in the ToolboxBrowser if you have many open browsers.
T.y. for you work and answers.
Post Reply