Behaviors not work for anonymous users I have a script with a behavior which receive settings by a block. The problem is that when I'm logged as admin the behavior is executed but when I'm an anonymous user, the behaviors isn't executed.

Can you help me ?

I Define this block :

public function build() {
        $config = $this-&gt;getConfiguration();

        // Check if the conf
        if (empty($config['token']) || empty($config['pagename']) || empty($config['pageurl']) || empty($config['limit']))
            return array('err' =&gt; array('#markup' =&gt; t('You must configure the block.')));

        $build = [];
        // Create the wrapper to include facebook posts
        $build['facebook']['timeline']['#markup'] = '&lt;div id="myc-fb-posts" class="slider"&gt;&lt;ul class="slides"&gt;&lt;/ul&gt;&lt;/div&gt;';
        // Push conf vars
        foreach ($config as $key =&gt; $value) {
            $build['#attached']['drupalSettings']['myc_fb'][$key] = $value;
        }
        // Includes libraries
        $build['#attached']['library'][] = 'myc_facebook/myc_facebook';

        return $build;
    }


And here is my js :

jQuery(document).ready(function($) {
    console.log("hello 1");
    console.log(Drupal);
    Drupal.behaviors.myc_facebook = {
        attach: function (context, settings) {
            console.log("hello 2");     
    };
});


And it's how I define my library :

myc_facebook:
  version: 1.x
  js:
    js/script.js: {}
    js/timeago.js: {}
  dependencies:
    - core/drupal
    - core/jquery
    - core/drupalSettings
You probably need to pass a reference of jQuery and Drupal in your js file like this:

(function ($, Drupal, drupalSettings) {

  ...

})(jQuery, Drupal, drupalSettings);


Btw. your js has {{{ but only }}. And you don't need document ready when you use drupal behaviors.